GridBoundColumn with multiple DataFields

谁说我不能喝 提交于 2019-12-11 00:19:56

问题


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.


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



回答2:


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



来源:https://stackoverflow.com/questions/3450181/gridboundcolumn-with-multiple-datafields

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!