Friday, July 31, 2009

How do you set and get the item data of an item in a listbox control in .NET (C#)?

you can use the %26lt;listboxControlID%26gt;.Items attribute...


note that Items is a list..so you can access it using indexes..


such as %26lt;listboxControlID%26gt;.Items[0].. and from there you can use the different methods such as %26lt;listboxControlID%26gt;.Items.Add()





And to get the values..you can use %26lt;listboxControlID%26gt;.SelectedItem





or you can loop through it





foreach(ListItem li in %26lt;listboxControlID%26gt;.Items)


{


//li.Text


}








Hope this helps..

strawberry

No comments:

Post a Comment