Reputation: 9309
I have a listbox named lbselectedcom in my web page. and i am binding some data to this list box by using a data table. this datatable named dt have 3 fields -name,ID,Score
lbSelectedCom.DataTextField = "Name";
lbSelectedCom.DataValueField = "ID";
lbSelectedCom.DataSource = dt.DefaultView;
lbSelectedCom.DataBind();
It works fine.Now i want to get score of the corresponding name with their ID. ID will get easily by using selected value property. Is there any way to bind Score field like ID in datavaluefield?? So that i can easily access score of each selected item like accessing ID by using selected value property
Upvotes: 0
Views: 2238
Reputation:
Another way would be to create a new view from dt, apply a filter on the ID selected, get the record and the field's value you need from the new view.. you can finally even choose to keep the new view and just refresh its filter condition for further selection values.
Advantage of this method would be that you can get to 'any' field of the selected item's corresponding datatable row.
Upvotes: 1
Reputation: 22709
You can add a new column to your datatable. And set the value of that column to be concatenation of ID and score separated by some delimiter.
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression(VS.71).aspx
Upvotes: 2