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();
加载中,请稍侯......
精彩评论