效果展示如下:

aspx頁面代碼:
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" Tagxmlns="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();
}
新聞熱點
疑難解答