Ext.Net动态加载多表头

 效果展示如下: 

aspx页面代码:

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>数据展示(版本3)</title>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:GridPanel ID="gpList" runat="server"  Title="" IconCls="icon-grid" AnimCollapse="false" Collapsible="true"  SortableColumns="true" AutoHeight="true" Width="3000">
        <Store>
            <ext:Store ID="StoreAll" runat="server" OnRefreshData="MyData_Refresh">
                <Model>
                    <ext:Model ID="Model1" runat="server">
                        <Fields>
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        </Store>       
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
            </Columns>
        </ColumnModel>
        <SelectionModel>
            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" PruneRemoved="false" Mode="Multi" />
        </SelectionModel>
    </ext:GridPanel>
    </form>
</body>
</html>

aspx.cs文件代码:

if (!IsPostBack)
{
  //清除旧数据与记录集
      this.StoreAll.Reader.Clear();
      this.gpList.SelectionModel.Clear();
      this.gpList.ColumnModel.Columns.Clear();
      this.StoreAll.Model.Clear();

  DataTable dtProject = new PerforBLL().GetData();//从数据库中读取的数据

  //数据源
     DataTable results = new DataTable();
     results.Columns.Add("Name");

  //数据集Store
  Model extModel = new Model();
  extModel.Fields.Add(new ModelField("Name", ModelFieldType.String));
  
  //显示的列数据
  List<ColumnBase> extColumnBaseList = new List<ColumnBase>();
  extColumnBaseList.Add(new RowNumbererColumn() { ID = "RowNumbererColumn1", Width = 25 });
  extColumnBaseList.Add(new Column() { ID = "cName", Text = "名称", Width = 300, DataIndex = "Name" });

  Column wZJ= new Column() { ID = "cWHZ", Text = "汇总" };

  extModel.Fields.Add(new ModelField("W-T", ModelFieldType.Float));
      extModel.Fields.Add(new ModelField("W-P", ModelFieldType.Float));

      if (!results.Columns.Contains("W-T")) results.Columns.Add("W-T");
      if (!results.Columns.Contains("W-P")) results.Columns.Add("W-P");

       wZJ.Columns.Add(new Column()
       {
         Text = "时间",
             Width = 50,
             DataIndex = "W-T",
             Sortable = true
       });
       wZJ.Columns.Add(new Column()
       {
         Text = "成本",
             Width = 50,
             DataIndex = "W-P",
             Sortable = true
  });

  extColumnBaseList.Add(wZJ);

  //动态给数据

  foreach (DataRow drProject in dtProject.Rows)
     {
    DataRow dr = results.NewRow();
           dr["Name"] = drProject["Name"];
    dr["W-T"]= 0;
           dr["W-P"] = 0;

    results.Rows.Add(dr);

  }

  this.StoreAll.Model.Add(extModel);
      this.gpList.ColumnModel.Columns.AddRange(extColumnBaseList);
      this.StoreAll.DataSource = results;
      this.StoreAll.DataBind();
      this.gpList.Render();

}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。