Is it possible to put multiple values in a DataValueField?
For example, with the following code:
<asp:DropDownList ID="ixTeam" CssClass="ixTeam" runat="server" DataSourceID="dsixTeam"
DataValueField="TeamID" DataTextField="TeamName" AppendDataBoundItems="true">
Is it possible for me to put two values (e.g. TeamID + "|" + TeamTypeID
) into the DataValueField?
You can't combine two fields in DataValueField
, but you can try couple of things.
SQL query:
Select (TeamID +"|"+ TeamTypeID) as CombinedTeam, .....`
and then set
DataFieldValue = "CombinedTeam"
Or
for example:
var query = from t in yourDataSource
select new
{
CombinedTeam = t.TeamID + "|" + t.TeamTypeID,
}
Then specify the data source for the drop down to the LINQ query, and specify the DataFieldValue
yourDropDownList.DataSource = query;
yourDropDownList.DataFieldValue = "CombinedTeam";
The short answer is you cannot.
Instead, create a calculated column in your dataset which has TeamID + '|' + TeamTypeID
for its expression (you can also do this when you fetch the data adding a formatted display column to your select query, assuming you are using a database), then bind on that column instead.
Yes, it can be done. Either format your data when retrieving from SQL server as following:
Select TeamID + ' | ' + TeamTypeID CombinedColumn
Now set the DataValueField=CombinedColumn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With