Monday, March 16, 2009

How to Get the Selected Item in a ListBox Control(ASP.NET 2.0,3.5 C#)

Many People who start developing on ASP.NET C#, they usually find it difficult to bind and get the selected item in the listbox and Dropdownlist control. This is how simple it is


String myselecteditem = listBox1.SelectedItems;



And you can do the same thing with a Dropdownlist


String mydropdownlist = dropdownlist1.SelectedItems;



Now all this will return what a user see on the List box, if it’s a list of numbers like {1,2,3,4,5} then the value that will be contained in there is that.


Thanks

No comments:

Post a Comment