Hi all,
I am just wondering why the below code is not working when i make a mulitple selectin from a list box. when i make a single selection it works fine. if you have any idea pls let me know and thanks for your help
<%@ Import namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb"%>
<html>
<head><title>Multiple Selections</title></head>
<body>
<h3>Multiple Selections</h3>
<form id="Form1" runat="server">
<asp:listBox id = "lstListBox"
selectionmode=Multiple
AutoPostBack="false"
Runat="server" AppendDataBoundItems="True" >
<asp:ListItem Value="state">-- State--</asp:ListItem>
</asp:listBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" /><br/><br/>
<asp:gridview id="gvEmployee" runat="server" >
<Columns>
<asp:BoundField />
</Columns>
</asp:gridview>
</form>
</body>
</html>
<script language="
vb" runat="server">
Dim myConnection As OleDbConnection
Dim connectionString As String
Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
' Dim txtstring As String
' txtstring = TextBox1.Text
If Not IsPostBack Then
connectionString = "provider=MSDAORA;Data Source=xx;User ID=xx;Password=xx;"
Dim objConnection As New OleDbConnection(connectionString)
Dim strSQLforListBox As String = "SELECT distinct astate FROM VENDADDR ORDER BY astate"
objConnection.Open()
Dim objCommand As New OleDbCommand(strSQLforListBox, objConnection)
lstListBox.DataSource = objCommand.ExecuteReader()
lstListBox.DataTextField = "astate"
lstListBox.DataValueField = "astate"
lstListBox.DataBind()
objConnection.Close()
End If
End Sub
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
' Remove next line prior to deployment
' Response.Write("subListChange triggered")
Dim strWhereClause As String = ""
Dim liThisOne As ListItem
For Each liThisOne In lstListBox.Items
If liThisOne.Selected Then
'strWhereClause += "astate=" & liThisOne.Value & " OR "
strWhereClause += liThisOne.Value & " OR "
End If
Next
' Remove next line prior to deployment
' Response.Write("strWhereClause = <br/>" & strWhereClause & "")
If strWhereClause.Length > 0 Then
gvEmployee.Visible = True
strWhereClause = Left(strWhereClause, strWhereClause.Length - 4)
'strWhereClause = "WHERE " & strWhereClause
connectionString = "provider=MSDAORA;Data Source=ss;User ID=ss;Password=ss;"
Dim strSQLforGrid As String = "SELECT vendor,astate FROM VENDADDR where astate=" & "'" & strWhereClause & "'"
Dim objConnection As New OleDbConnection(connectionString)
objConnection.Open()
Dim objCommand As New OleDbCommand(strSQLforGrid, objConnection)
' Remove next line prior to deployment
' Response.Write("strSQLforGrid = <br/>" & strSQLforGrid & "")
gvEmployee.DataSource = objCommand.ExecuteReader()
gvEmployee.DataBind()
objConnection.Close()
Else
gvEmployee.Visible = False
End If
End Sub
</script>