I have a GridBoundColumn that I would like to be bound to 2 fields so that I can display the two fields in one column. I would like to do something like the following:
<GridBoundColumn DataField1="LastName" DataField2="FirstName" DataFormatString="{0},{1}">
Is this possible? If so how can it be accomplished?
This is used in a Telerik RadGrid if that makes any difference.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
This can be accomplished by implementing the OnItemDataBound method (configured in your grid definition like OnItemdataBound="GridItemDataBound").
Make sure that the field is uniquely identified:
<GridBoundColumn UniqueName="UserName">
Then implement your OnItemDataBound method:
protected void GridItemDataBound(object aSender, GridItemEventArgs anEventArgs)
{
if(anEventArgs is GridDataItem)
{
string firstName = "Joe";
string lastName = "Smith";
GridDataItem item = (GridDataItem)anEventArgs.Item;
item["UserName"].Text = lastName + "," + firstName;
}
}
Method 2
You can also use a template column if you don’t want to write C# code.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0