Click here to Skip to main content
15,904,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I just want to know index value of Selected listbox item in VS2005.

could anyone help me.
Posted
Comments
Muralikrishna8811 26-Apr-12 5:36am    
Hi ,

just use existing property like listbox1.selectedIndex
SDAP_INDIA 26-Apr-12 5:43am    
dear that's not working, i need selected items index value....
SDAP_INDIA 26-Apr-12 5:44am    
i tried very...in all ways..

Hi,

use this

listbox1.SelectedItems.IndexOf(lv);

Regards
Aravind G
 
Share this answer
 
Comments
SDAP_INDIA 26-Apr-12 7:17am    
Its working but i have binded my listbox with sql values like

if (!Page.IsPostBack)
{
str = "select * from TBL_NM_State where StateId<112";
cmd = new SqlCommand(str, con);
DataSet ds = new DataSet();
da.SelectCommand = cmd;
con.Open();
da.Fill(ds, "TB1");
Lst1.DataSource = ds.Tables[0].DefaultView;
Lst1.DataTextField = "Statename";
Lst1.DataValueField = "Statename";
Lst1.DataBind();

}

if (Lst1.SelectedIndex > -1)
{
Int32 idx = Lst1.SelectedIndex;
}

values are there but could not finding index values after clicking on particular item

( I think my sql values are not a part of items collection)
Member 13400846 22-May-20 9:49am    
please help if u get the ans. i am also facing the same error
Int32 idx = Lst1.Items.IndexOf(Lst1.SelectedItem);
 
Share this answer
 
myListBox.Items.FindByValue(value)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900