I am coding in VB
I have a listbox with multiselect enabled.
I am able to verify I have captured multiple values by displaying them in a label- the code behind is fired OnSelectedIndexChanged event in Listbox:
What I want to do is use the values from the Listbox in the WHERE statement (I am sure I will be able to use IN but don't know how to deliver the values) to filter a gridview. At the moment, it changes to give me only one of the selections from the listbox, not all of them:
I have a listbox with multiselect enabled.
Code:
<asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Requirements_Heading"
DataValueField="ID" AutoPostBack="true" SelectionMode="Multiple" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" Rows="8"></asp:ListBox>
<asp:SqlDataSource runat="server" ID="SqlDataSource1"
I am able to verify I have captured multiple values by displaying them in a label- the code behind is fired OnSelectedIndexChanged event in Listbox:
Code:
Dim stringBuilder = New StringBuilder()
Dim delimiter = ", "
For Each item As ListItem In ListBox1.Items
If item.Selected Then
stringBuilder.AppendFormat("{0}{1}", item, delimiter)
End If
Next
Label1.Text = "These are the requirements you have selected: " & stringBuilder.ToString()
What I want to do is use the values from the Listbox in the WHERE statement (I am sure I will be able to use IN but don't know how to deliver the values) to filter a gridview. At the moment, it changes to give me only one of the selections from the listbox, not all of them:
Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="Company Name" HeaderText="Company Name" SortExpression="Company Name"></asp:BoundField>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" InsertVisible="False" SortExpression="ID"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource runat="server" ID="SqlDataSource2"
ConnectionString='<%$ ConnectionStrings:HSCConvertedConnectionString %>'
SelectCommand="SELECT tblCompany.CompanyName, tblSupplierMapCodes.ID FROM ... WHERE (tblSupplierMapCodes.ID = @ID)">
<SelectParameters>
<asp:ControlParameter ControlID="ListBox1" PropertyName="SelectedValue" Name="ID"></asp:ControlParameter>
</SelectParameters>
</asp:SqlDataSource>