I have a table with these fields: id, name
I have built a listback in the table.
My question is, when the user has selected an item in the list, how will I know what is the ID of the chosen item?
Note: ID is not equal to the selected index or items of items are not in the ID
< P> Eg Assume that you have a datatable dt, it has column ID and name. Then binding contains the following code,
this.listbox.DataSource = dt; This.listbox.DisplayMember = "name"; This.listbox.ValueMember = "id"; While reading selected values for the listbox,
this.listbox.SelectedItem will give you the selected name and
this.listbox.SelectedValue will give you the relevant ID
Comments
Post a Comment