首页 > 学院 > 开发设计 > 正文

Ext.Net动态加载多表头

2019-11-17 01:44:01
字体:
来源:转载
供稿:网友

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();

}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表