What I'm trying to do is to select multiple countries from listbox, then hit select, then a gridview would pull out data from a table based on the countries selected. my problem is that I don't know how to pass the string where country in (A,B,C,...) into a SQL Server stored procedure. Any advice on this would be great!
My listbox is
<asp:ListBox ID="Country" cssclass="LBox" runat="server" SelectionMode="Multiple">
<asp:ListItem Text="A" Value="A" />
<asp:ListItem Text="B" Value="B" />
<asp:ListItem Text="C" Value="C" />
<asp:ListItem Text="D" Value="D" />
..............
</asp:ListBox>
My select button is
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim li As ListItem
Dim myString As String = ""
Dim myString2 As String = ""
For Each li In ListBoxComp.Items
If li.Selected = True Then
If myString = "" Then
myString = "'" & li.Text & "'"
Else
myString = myString & ", " & "'" & li.Text & "'"
End If
End If
Next
myString2 = myString2
Session("Selected") = myString2
My gridview is
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" BackColor="White"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
CellPadding="3" DataSourceID="SqlDataSource1" ForeColor="Black"
GridLines="Vertical">
......
</asp:GridView>
Datasource is
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="usp_select" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="myString2" SessionField="Selected" />
</SelectParameters>
</asp:SqlDataSource>
SQL Server stored procedure is
ALTER PROCEDURE [dbo].[usp_select]
@myString2 varchar(5000)
AS
BEGIN
SELECT *
FROM dbo.table
WHERE country IN (@myString2)
END
My problem is that I don't know how to pass the string where country in (A,B,C,...) into the SQL Server stored procedure. Any advice on this would be great!