Hi There,
I have a page control with 2 listmenus on it, when the page loads the
I get the error expression expected, I am trying to pass the values of
a listbox to a page control when the user selects the menu. At the
moment I'm not sure what I have missed.
Sean - thanks in advance
!--- error
Line 29:
Line 30:
Line 31: strSelectedCategories = <%# lstCategorie.ClientID
%>.SelectedItem.Value
Line 32: strSelectedStates = <%# lstStates.ClientID
%>.SelectedItem.Value
Line 33:
---Suspect lines of code
strSelectedCategories = <%# lstCategorie.ClientID
%>.SelectedItem.Value
strSelectedStates = <%# lstStates.ClientID
%>.SelectedItem.Value
!--- page code
<%@ Control Language="vb" EnableViewState="False" %>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
Public ReadOnly Property SelectedCategoriesID As String
Get
return lstCategorie.ClientID
End Get
End Property
Public ReadOnly Property SelectedStatesID As String
Get
return lstStates.ClientID
End Get
End Property
Public Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack Then
BindStates()
LoadCategories()
Else
Dim strFormID as Integer
Dim strSelectedStates as Integer
Dim strSelectedCategories as Integer
'response.write (lstCategorie.ClientID.SelectedItem.Value)
strSelectedCategories = <%# lstCategorie.ClientID
%>.SelectedItem.Value
strSelectedStates = <%# lstStates.ClientID
%>.SelectedItem.Value
If strSelectedStates <> "0" AND strSelectedCategories ="0" Then
strFormID = strSelectedStates
SendUserToState(strFormID)
Elseif strSelectedStates = "0" AND strSelectedCategories <> "0"
Then
'response.write ("categories")
'response.end
strFormID = strSelectedCategories
SendUserToCategorie(strFormID)
End If
End If
End Sub
Public Function SendUserToState(ByVal strFormID as Integer)
Select Case strFormID
Case 1,2,3,4,5,6,7,8,9
response.redirect("browselistingsbystate.aspx?StateID=" &
strFormID)
Case Else
'do jack all
End Select
End Function
Public Function SendUserToCategorie(ByVal strFormID as Integer)
Select Case strFormID
Case 6,10,8,7,11,13,9,12
response.redirect("browselistings.aspx?CategoryID=" &
strFormID)
Case Else
'do jack all
End Select
End Function
Public Sub BindStates()
Try
Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Const strSQL as String = "SELECT LocationID, '...' + Location +
'...' AS Location " & _
"FROM
tbLocation ORDER BY Location"
Dim myCommand as New SqlCommand(strSQL, myConnection)
myConnection.Open()
Dim objDR as SqlDataReader
objDR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
lstStates.DataSource = objDR
lstStates.DataBind()
lstStates.Items.Insert(0, new ListItem("-- Choose a State
--","0"))
Catch ex as InvalidCastException
Status.Text = ex.ToString()
Catch ex As SqlException
Status.Text = "Database error: " & ex.message
Catch ex As Exception
Status.Text = "General error: " & ex.message
End Try
End Sub
Public Sub LoadCategories()
Try
Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Const strSQL as String = "SELECT CategoryID, '...' +
CategoryDesc +
'...' AS CategoryDesc " & _
"FROM
tblProductCategories ORDER BY CategoryDesc"
Dim myCommand as New SqlCommand(strSQL, myConnection)
myConnection.Open()
Dim objDR as SqlDataReader
objDR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
lstCategorie.DataSource = objDR
lstCategorie.DataBind()
lstCategorie.Items.Insert(0, new ListItem("-- Choose a Category
--","0"))
Catch ex as InvalidCastException
Status.Text = ex.ToString()
Catch ex As SqlException
Status.Text = "Database error: " & ex.message
Catch ex As Exception
Status.Text = "General error: " & ex.message
End Try
End Sub
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<td height="20" width="14%">
<div align="left">
<asp:listbox id="lstCategorie" runat="server" Rows="1"
AutoPostBack="true"
DataTextField="CategoryDesc" DataVa
lueField="CategoryID" />
</div>
</td>
<td height="20" width="11%">
<div align="right"><font face="Verdana, Arial, Helvetica,
sans-serif" size="1" color="#FFFFFF">Browse
:</font></div>
</td>
<td height="20" width="14%">
<div align="left">
<asp:listbox id="lstStates" runat="server" Rows="1"
AutoPostBack="true"
DataTextField="Location" DataValueField="LocationID" />
</div>
</td>
<td height="20" width="17%">
<div align="center"><font face="Verdana, Arial, Helvetica,
sans-serif" size="1" color="#FFFFFF">
Search Site </font></div>
</td>
</tr>
</table>
<asp:Label id="status" runat="server"></asp:Label>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/