in aspx.cs
string CatID = string.Empty;
foreach (ListItem li in ListBox1.Items)
{
if (li.Selected == true)
{
// get the value of the item in your loop
CatID += li.Value + ",";
}
}
In aspx
<asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource1" SelectionMode="Multiple"
DataTextField="Username" DataValueField="Username" Height="175px"
Width="167px"></asp:ListBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>"
SelectCommand="SELECT * FROM [login_det] WHERE ([Type] = @Type)">
<SelectParameters>
<asp:Parameter DefaultValue="User" Name="Type" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
A piece of code is shown above which will give the output as abc,bcd,efg,hig,
when I select four items in the list box. Now is there any possibilities of retrieving these values individually and store it as a string?.Like`
string a = “abc”;
String b=”bcd”;
String c=”efg”;` etc.
Another conflict occurs is that there may be 100’s of items in the list box.and if I select 90 items I should declare or assign the each items with a string variable,which is meaningless.But is there any other possibility of storing or retrieving individual items from the list box?