开发者

Is there anyway to bind multiple values to value field of a listbox -C# and ASP>NET

开发者 https://www.devze.com 2023-01-30 01:44 出处:网络
I have a listbox named lbselectedcom in my web page. and开发者_StackOverflow社区 i am binding some data to this list box by using a data table.this datatable named dt have 3 fields -name,ID,Score

I have a listbox named lbselectedcom in my web page. and开发者_StackOverflow社区 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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消