开发者

Change only the DataValueField of a Listbox?

I have a Listbox

dimension.DataSource = provider.DimensionList;
dimension.DataBind();

I want the value to be the ID of these elements

dimension.DataSource = provider.DimensionList;
dimension.DataValueField = "ID";
dimension.DataBind();

But I don't 开发者_如何学Pythonwant the text to change to the ID, I want that the dimension.DataTextField gets the object.ToString().

How can this be done?


I don't know exactly the type of the DimensionList, but I believe that you could use a select that will return an anonymous type:

dimension.DataSource = provider.DimensionList.Select(d=>new {Id=d.Id,Text=d.ToString()}).ToList();
dimension.DataValueField = "Id";
dimension.DataTextField = "Text";
dimension.DataBind();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜