在RadGrid中更改自动生成的数据绑定列的标题文本

时间:2011-09-27 18:20:52

标签: radgrid

如何在RADGRID中更改自动生成的DataBound列的标题文本。我正在加载数据集whoz列是自动生成的(Wgt1,Wgt2,Wgt3 .......)。我希望这些列标题为

Wgt | abc | Wgt | edg | Wgt | .......目前正在进行中

Wgt1 | abc | Wgt2 | edg | Wgt3 | .......

我试过

If(TypeOf e.Item是GridDataItem)然后
For Each column1 As GridColumn In e.Item.OwnerTableView.RenderColumns
Dim dataItem As GridDataItem = DirectCast(e.Item,GridDataItem)
如果column1.HeaderText =“Wgt1”那么
dataItem(“Wgt1”)。Text =“Wgt”
结束如果
接下来
结束如果

但这改变了列数据而不是标题文本

1 个答案:

答案 0 :(得分:2)

    protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
                    new { ID = 1, Name ="Name1"},
                    new { ID = 2, Name = "Name2"},
                    new { ID = 3, Name = "Name3"},
                    new { ID = 4, Name = "Name4"},
                    new { ID = 5, Name = "Name5"}
                };


            RadGrid2.DataSource = data;
        }
        protected void RadGrid2_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
        {
            if (e.Column.UniqueName == "Name")
            {
                e.Column.HeaderText = "Jayesh";
            }
        }