开发者

GridBoundColumn with multiple DataFields

开发者 https://www.devze.com 2023-01-10 19:19 出处:网络
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:

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.


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;
   }
}


You can also use a template column if you don't want to write C# code.

0

精彩评论

暂无评论...
验证码 换一张
取 消