selected index changed in listbox control
-
hii, i placed the listbox control in the webform. and i added some code in the ListBox1_SelectedIndexChanged but the problem that when i select the different items in the list it doesn't infoke the methode and i tried to debuge it and i found that the selectedindex is always = -1
-
hii, i placed the listbox control in the webform. and i added some code in the ListBox1_SelectedIndexChanged but the problem that when i select the different items in the list it doesn't infoke the methode and i tried to debuge it and i found that the selectedindex is always = -1
-
i tried to set autopostback to true and works for the pre defined items in the collection in design mode but if in run time if i clear the listbox items and fill it in the run time using the .Add() method it give me selectedindex=-1
It sounds like in the page_load method you are populating the listbox. You need to have some code that checks for postback. Something like:
If (!IsPostBack)
{
//then add items to listbox
}Otherwise you are constantly re-loading your listbox everytime you postback to the web server not just the first page load. Hope that helps. Ben
-
It sounds like in the page_load method you are populating the listbox. You need to have some code that checks for postback. Something like:
If (!IsPostBack)
{
//then add items to listbox
}Otherwise you are constantly re-loading your listbox everytime you postback to the web server not just the first page load. Hope that helps. Ben
dear kunnen first thanks for replay. i discovered the problem, the problem that i was clearing the list items and load the list in page load. so when i select the item the reload again then clear the list and this point the selectedindex goes -1 . so i put a condition that let it clear the list only one time when the page open thanks again