I have a table with these fields: 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 Assume that you have a datatable dt, it has column ID and name. Then binding contains the following code, While reading selected values for the listbox, id, name
< P> Eg
this.listbox.DataSource = dt; This.listbox.DisplayMember = "name"; This.listbox.ValueMember = "id";
this.listbox.SelectedItem will give you the selected name and
this.listbox.SelectedValue will give you the relevant ID
Comments
Post a Comment