【问题标题】:Add Columns Dynamically at specific index to existing RadGrid在现有 RadGrid 的特定索引处动态添加列
【发布时间】:2019-03-05 11:25:16
【问题描述】:

我必须在特定位置添加自定义列运行时以退出 Telerik 网格。

string[] customColumns = ds.Tables[2].Rows[0]["CustomColumns"].ToString().Split(',');
int startIndex = 7;
for (int i = 0; i < customColumns.Length; i++)
{
    GridBoundColumn NewColumn = new GridBoundColumn();
    tableGrid.MasterTableView.Columns.AddAt(startIndex, NewColumn);
    NewColumn.HeaderText = customColumns[i].Replace("[", "").Replace("]", "");
    NewColumn.DataField = customColumns[i].Replace("[", "").Replace("]", "");
    NewColumn.Visible = true;
    NewColumn.FilterControlWidth = Unit.Percentage(70);
    NewColumn.HeaderStyle.CssClass = "setHeader";
    NewColumn.HeaderStyle.Width = 130;
    NewColumn.AllowFiltering = true;
    NewColumn.OrderIndex = startIndex;
    startIndex++;
}

使用此代码块在给定位置成功添加了列,但是当我使用现有的网格过滤器功能时,列的位置发生了变化,甚至我看不到列中的值。

【问题讨论】:

    标签: asp.net telerik telerik-grid


    【解决方案1】:

    您需要为列定义一个 OrderIndex,当向网格添加新的时,您将知道要使用哪个 OrderIndex。查看Reordering columns programmatically 文章供您参考。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-29
      • 2011-07-05
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 2013-01-21
      相关资源
      最近更新 更多