List Box
-
I have a list box control on a web form that displays some data from a database. Each time a different item is selected in this list box I want to display some data in another list box, so I am handeling the SelectedIndexChanged event. My problem is that the event doesn't seem to be firing. This is what I am using:
protected void GroupList\_SelectedIndexChanged(object sender, EventArgs e) { //get what group has been selected int index = GroupList.SelectedIndex; // get all the items in the group DataRow\[\] rows = dSet.Tables\["Mounts"\].Select("Group\_Number =" + GroupList.Items\[index\].Text); // Clear the second list of any items foreach (ListItem item in MountList.Items) { MountList.Items.Remove(item); } //Display the new list foreach (DataRow row in rows) { MountList.Items.Add(row\[0\].ToString()); } }
When I run this and select different items in the list box, nothing happens. Any ideas why? Thanks for any responses ;)
-
I have a list box control on a web form that displays some data from a database. Each time a different item is selected in this list box I want to display some data in another list box, so I am handeling the SelectedIndexChanged event. My problem is that the event doesn't seem to be firing. This is what I am using:
protected void GroupList\_SelectedIndexChanged(object sender, EventArgs e) { //get what group has been selected int index = GroupList.SelectedIndex; // get all the items in the group DataRow\[\] rows = dSet.Tables\["Mounts"\].Select("Group\_Number =" + GroupList.Items\[index\].Text); // Clear the second list of any items foreach (ListItem item in MountList.Items) { MountList.Items.Remove(item); } //Display the new list foreach (DataRow row in rows) { MountList.Items.Add(row\[0\].ToString()); } }
When I run this and select different items in the list box, nothing happens. Any ideas why? Thanks for any responses ;)
-
Possible clauses. - How you handle the initliazation. - If its running it on the server this function. - If this method isnt being added on the specific control.
-
Well, more of the case of Web Forms how you need to check if your reloading those Listboxes again, and if so that whenever you reload the page again, it might reload those items again and reset whatever changes you want in the first place. Another issue becomes if its stateless or not (meaning does it retain the data when you press on buttons, that go back to the server to process things and spit back out the result on the WebForm that you asked for). Web Forms are really difficult to determine where your problem is. You need to check how the flow of the web form works, but from hazarding a guess of why nothing is happening is most possibly that you are resetting those listboxes to that nothing is happening. But this is just guessing, it'd be better with a full code rather than a specific method, but thats your call. Kuira