Last post Sep 08, 2007 09:34 AM by kaushalparik27
Sep 07, 2007 03:46 AM|cmrhema|LINK
I am working in asp.net 2.0 and visual C# 2005
I am selecting multiple items in a list box.
Now I want a count of the seleted items also the index of the selected item
I browsed and found something called
" selectedindices.count "
but unfourtunately when i type listbox1 the selectedindices does not popup.
I did write ListBox1. but all i could trace was
selectedindices seems nowhere in the list
Any help please
thanks and regards
Sep 07, 2007 04:17 AM|Sweeperq|LINK
Dim i As Integer = 0
Dim cnt As Integer = 0
For i=0 To ListBox1.Items.Count-1
If ListBox.Items(i).Selected Then
'Do something with the selected item
cnt += 1
Sep 07, 2007 04:39 AM|rakeshkmbj|LINK
Sep 07, 2007 08:42 AM|suman.r|LINK
I think its better you use a checkboxlist for ur multiple selects ...then u can do
Sep 08, 2007 06:55 AM|cmrhema|LINK
the below code gives you the count of selected items
Now i want to know the index of the selected items.
listcount = listcount + 1;
Sep 08, 2007 09:34 AM|kaushalparik27|LINK
I want a count of the seleted items
you can use ListBox1.GetSelectedIndices().Length to get count of selected items.
and the index of the selected item
you can use ListBox1.GetSelectedIndices() to get the selected items' index in an array (type int)....
try this out...
protected void Button2_Click(object sender, EventArgs e)
Response.Write("<br />" + ListBox1.GetSelectedIndices().Length.ToString());
int intSelectedIndexes = new int[ListBox1.GetSelectedIndices().Length];
intSelectedIndexes = ListBox1.GetSelectedIndices();
for (int iCount = 0; iCount < intSelectedIndexes.Length; iCount++)
Response.Write("<br />" + intSelectedIndexes[iCount].ToString() + " Index Selected");
hope it helps./.