Combining two fields in a DataTextField. Is this possible?
Ans : Yes
Here is the code How to do this You can add an additional column to the datatable that is a computed column and use it as your datatextfield
So for your example above you could do something like this:
dsAddress.Tables[0].Columns.Add("StreetAndPlace",typeof(string),"StreetAddress + Place"); lstAddressDropdown.DataSource = dsAddress;
lstAddressDropdown.DataTextField = "StreetAndPlace";
lstAddressDropdown.DataBind();
lstAddressDropdown.Items.Insert(0, new ListItem("Please select"));
To add a space Or any special characters between the StreetAddress and Place replace the expression string shown above with "StreetAddress + ' ' + Place" Or "StreetAddress + '$' + Place"
Ans : Yes
Here is the code How to do this You can add an additional column to the datatable that is a computed column and use it as your datatextfield
So for your example above you could do something like this:
dsAddress.Tables[0].Columns.Add("StreetAndPlace",typeof(string),"StreetAddress + Place"); lstAddressDropdown.DataSource = dsAddress;
lstAddressDropdown.DataTextField = "StreetAndPlace";
lstAddressDropdown.DataBind();
lstAddressDropdown.Items.Insert(0, new ListItem("Please select"));
To add a space Or any special characters between the StreetAddress and Place replace the expression string shown above with "StreetAddress + ' ' + Place" Or "StreetAddress + '$' + Place"
Comments
Post a Comment