问题描述
我有,我想绑定到2场,这样我可以在一列显示两个字段GridBoundColumn。我愿做类似如下:
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?
这是在Telerik的radgrid控件使用,如果有什么差别。
This is used in a Telerik RadGrid if that makes any difference.
推荐答案
这可以通过实现OnItemDataBound方法来完成(在网格定义配置如 OnItemdataBound =GridItemDataBound
)。
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">
然后实现您的OnItemDataBound方式:
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;
}
}
这篇关于与多个数据域GridBoundColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!