I have a drop down list that is populated with data in the code behind. The DataTextField attribute is set with the following code:
ddlItems.DataTextField = "ItemName";
I want to display two data properties as the DataTextField. I tried using the following code but it didn’t work. And I have researched on the net but couldn’t find how to use two data properties.
ddlItems.DataTextField = "ItemName" + "ItemDescription";
What code do I need to use to do this?
You can use the Formatting event of ddlItems which will allow you to set logic to how to convert a certain item to a string, or if it makes any sense to use in your program, have a property like RepresentingString that returns Name + Desc, and bind to that property.
Similar question with more answers and code examples:
Format DropDownList.TextValue