在使用UltraWebGrid 很麻烦,很多人说这年控件很强大,但我觉的一点都不好用,前几天用到了Grid的层级关系的时候,
使用到了它,Infragistics 的层级的中文资料少之又少,好像没有哦,
页面代码:
- <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Rpt_CaseInfoByDeptLevel.aspx.cs"
- Inherits="SZUM.ZHZF.Web.IntergratedCasePlatform.Pages.Report.Rpt_CaseInfoByDeptLevel" %>
- <%@ Register Assembly="Infragistics2.WebUI.UltraWebGrid.v5.3, Version=5.3.20053.73, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
- Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %>
- <%@ Register TagPrefix="igtblex" Namespace="Infragistics.WebUI.UltraWebGrid.ExcelExport"
- Assembly="Infragistics2.WebUI.UltraWebGrid.ExcelExport.v5.3" %>
- <!-- ie QuirksMode -->
- <!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">
- <title>Untitled Page</title>
- </head>
- <script language="JavaScript">
- window.onerror=function(){return true;}
- </script>
- <body>
- <form id="form1" runat="server">
- <div class="box_layer_5">
- <div class="relative">
- <h1 class="b_title">
- <code>部门统计报表</code></h1>
- <div class="box_content">
- <div class="search_box padding_bottom_10px">
- <table cellpadding="0" cellspacing="8" border="0">
- <tr>
- <th style="width: 60px">
- 区 域:
- </th>
- <td>
- <div class="selectbox_width_120px">
- <asp:DropDownList ID="ddlRegion" runat="server">
- </asp:DropDownList>
- </div>
- </td>
- <th style="width: 60px">
- 受理时间:</th>
- <td>
- <asp:TextBox ID="txtStart" runat="server" onclick="WdatePicker()" CssClass="Wdate"
- Width="110px"></asp:TextBox>
- </td>
- <td>
- 至<asp:TextBox ID="txtEnd" runat="server" onclick="WdatePicker()" CssClass="Wdate"
- Width="110px"></asp:TextBox></td>
- <td id="btn_style_control">
- <asp:Button ID="BtnCreate" runat="server" OnClick="BtnCreate_Click" CssClass="btnStyle"
- Text="查 询" />
- <asp:Button ID="BtnToExcel" runat="server" OnClick="BtnToExcel_Click" CssClass="btnStyle"
- Text="导出Excel" />
- <asp:Button ID="btnToOfficeExcel" runat="server" CssClass="btnStyle" Text="导出OfficeExcel"
- OnClick="btnToOfficeExcel_Click" Visible="False" />
- </td>
- </tr>
- </table>
- </div>
- <div class="grid_list_content_top_59px">
- <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Width="100%" Browser="UpLevel">
- <DisplayLayout RowHeightDefault="18px" Version="3.00" SelectTypeRowDefault="Single"
- ViewType="Hierarchical" BorderCollapseDefault="Separate" LoadOnDemand="Manual"
- Name="UltraWebGrid1" AutoGenerateColumns="False" ColWidthDefault="152px">
- <RowSelectorStyleDefault Width="10px" VerticalAlign="Middle" Font-Size="8pt" Font-Names="Verdana"
- HorizontalAlign="Center" BackColor="Gray">
- </RowSelectorStyleDefault>
- <ActivationObject BorderColor="168, 167, 191">
- </ActivationObject>
- <RowExpAreaStyleDefault Font-Size="8pt" Font-Names="Verdana" BackColor="White">
- </RowExpAreaStyleDefault>
- <EditCellStyleDefault BorderWidth="0px" BorderStyle="None">
- </EditCellStyleDefault>
- <RowAlternateStyleDefault BackColor="#F1F1F1">
- </RowAlternateStyleDefault>
- <RowStyleDefault BorderWidth="0px" Font-Size="8pt" Font-Names="Verdana" BorderColor="DarkGray"
- BorderStyle="Solid" ForeColor="Black" BackColor="Gainsboro">
- <Padding Left="7px" Right="7px"></Padding>
- <BorderDetails ColorTop="White" WidthLeft="0px" WidthTop="0px" ColorLeft="Gray"></BorderDetails>
- </RowStyleDefault>
- </DisplayLayout>
- <Bands>
- <igtbl:UltraGridBand>
- <Columns>
- <igtbl:UltraGridColumn BaseColumnName="region_id" HeaderText="部门" IsBound="True"
- Hidden="True" Key="region_id">
- <Header Caption="部门">
- </Header>
- </igtbl:UltraGridColumn>
- <igtbl:UltraGridColumn BaseColumnName="dept_name" HeaderText="部门" IsBound="True"
- Key="dept_name">
- <Header Caption="部门">
- <RowLayoutColumnInfo OriginX="1" />
- </Header>
- <Footer>
- <RowLayoutColumnInfo OriginX="1" />
- </Footer>
- </igtbl:UltraGridColumn>
- <igtbl:UltraGridColumn BaseColumnName="acceptcount" HeaderText="受理数" IsBound="True"
- Key="acceptcount">
- <Header Caption="受理数">
- <RowLayoutColumnInfo OriginX="2" />
- </Header>
- <Footer>
- <RowLayoutColumnInfo OriginX="2" />
- </Footer>
- </igtbl:UltraGridColumn>
- <igtbl:UltraGridColumn BaseColumnName="basiccount" HeaderText="立案数" IsBound="True"
- Key="basiccount">
- <Header Caption="立案数">
- <RowLayoutColumnInfo OriginX="3" />
- </Header>
- <Footer>
- <RowLayoutColumnInfo OriginX="3" />
- </Footer>
- </igtbl:UltraGridColumn>
- <igtbl:UltraGridColumn BaseColumnName="endcount" HeaderText="结案数" IsBound="True"
- Key="endcount">
- <Header Caption="结案数">
- <RowLayoutColumnInfo OriginX="4" />
- </Header>
- <Footer>
- <RowLayoutColumnInfo OriginX="4" />
- </Footer>
- </igtbl:UltraGridColumn>
- <igtbl:UltraGridColumn BaseColumnName="nocreatecount" HeaderText="不予立案数" IsBound="True"
- Key="nocreatecount">
- <Header Caption="不予立案数">
- <RowLayoutColumnInfo OriginX="5" />
- </Header>
- <Footer>
- <RowLayoutColumnInfo OriginX="5" />
- </Footer>
- </igtbl:UltraGridColumn>
- <igtbl:UltraGridColumn BaseColumnName="movecount" HeaderText="移交数" IsBound="True"
- Key="movecount">
- <Header Caption="移交数">
- <RowLayoutColumnInfo OriginX="6" />
- </Header>
- <Footer>
- <RowLayoutColumnInfo OriginX="6" />
- </Footer>
- </igtbl:UltraGridColumn>
- <igtbl:UltraGridColumn BaseColumnName="stopcount" HeaderText="撤销中止数" IsBound="True"
- Key="stopcount">
- <Header Caption="撤销中止数">
- <RowLayoutColumnInfo OriginX="7" />
- </Header>
- <Footer>
- <RowLayoutColumnInfo OriginX="7" />
- </Footer>
- </igtbl:UltraGridColumn>
- </Columns>
- <AddNewRow View="NotSet" Visible="NotSet">
- </AddNewRow>
- </igtbl:UltraGridBand>
- </Bands>
- </igtbl:UltraWebGrid>
- <igtblex:UltraWebGridExcelExporter ID="UltraWebGridExcelExporter1" runat="server"
- ExcelStartRow="3">
- </igtblex:UltraWebGridExcelExporter>
- </div>
- </div>
- </div>
- </div>
- </form>
- </body>
- </html>
后台代码
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using Infragistics.WebUI.UltraWebGrid;
- using Infragistics.WebUI.UltraWebGrid.ExcelExport;
- using SZUM.ZHZF.Logic.CommonBaseClass;
- using SZUM.ZHZF.Entity.IntergratedCasePlatform;
- using SZUM.ZHZF.Logic.IntergratedCasePlatform;
- using System.Collections.Generic;
- using SZUM.ZHZF.Framework.Utility;
- namespace SZUM.ZHZF.Web.IntergratedCasePlatform.Pages.Report
- {
- public partial class Rpt_CaseInfoByDeptLevel : BaseCommonCaseHandlerPage
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- BindRegion();
- }
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.UltraWebGrid1.DemandLoad += new Infragistics.WebUI.UltraWebGrid.DemandLoadEventHandler(this.UltraWebGrid1_DemandLoad);
- this.UltraWebGrid1.InitializeLayout += new Infragistics.WebUI.UltraWebGrid.InitializeLayoutEventHandler(this.UltraWebGrid1_InitializeLayout);
- }
- #endregion
- private RegionInfoEntity _regionEntity;
- public RegionInfoEntity RegionEntity
- {
- get
- {
- if (_regionEntity == null)
- {
- _regionEntity = RegionInfoLogic.GetRegionIdByDeptId(PMIExtentionManager.LogonUser.User.DefaultDepartmentID);
- }
- return _regionEntity;
- }
- }
- private string _deptSQL = "";
- private string DeptSQL
- {
- get
- {
- if (_deptSQL == "")
- {
- _deptSQL = PMIExtentionManager.GetDepartmentCollectSql(PMIExtentionManager.LogonUser.User.DefaultDepartmentID);
- }
- return _deptSQL;
- }
- }
- private void BindRegion()
- {
- ddlRegion.Items.Clear();
- bool IsShi = false;//是否为市级
- RegionInfoEntity rootRegion = RegionInfoLogic.GetRegionColByParentId(Guid.Empty)[0];
- if (RegionEntity.RegionId == rootRegion.RegionId)
- {
- ddlRegion.Items.Add(new ListItem(rootRegion.RegionName, rootRegion.RegionId.ToString()));
- IsShi = true;
- }
- RegionInfoCollection districtCol = RegionInfoLogic.GetRegionColByParentId(rootRegion.RegionId);
- foreach (RegionInfoEntity i in districtCol)
- {
- if (RegionEntity.RegionId == i.RegionId || RegionEntity.ParentId == i.RegionId || IsShi)
- {
- ddlRegion.Items.Add(new ListItem(" " + i.RegionName, i.RegionId.ToString()));
- }
- }
- }
- protected void BtnCreate_Click(object sender, EventArgs e)
- {
- BindView();
- }
- private DataTable _GridSource = null;
- public DataTable GridSource
- {
- get
- {
- if (_GridSource == null)
- {
- Guid regionid = Guid.Empty;
- if (!string.IsNullOrEmpty(this.ddlRegion.SelectedValue))
- {
- regionid = new Guid(this.ddlRegion.SelectedValue);
- }
- DateTime dstart = new DateTime();
- if (!string.IsNullOrEmpty(this.txtStart.Text))
- {
- dstart = Convert.ToDateTime(this.txtStart.Text);
- }
- DateTime dend = new DateTime();
- if (!string.IsNullOrEmpty(this.txtEnd.Text))
- {
- dend = Convert.ToDateTime(this.txtEnd.Text);
- }
- //string deptsql = this.DeptSQL;
- //this.TextBox1.Text = deptsql;
- //if (this.ddlRegion.SelectedIndex == 0)
- //{
- // //深圳市
- // _GridSource = CalcCaseInfoByDeptReportLogic.GetDataTableByParmsBig(regionid, dstart, dend,deptsql);
- //}
- //else
- //{
- //区域
- _GridSource = CalcCaseInfoByDeptReportLogic.GetDataTableByParms(regionid, dstart, dend, this.DeptSQL);
- _GridSource = AddTableSmallSum(_GridSource);
- //}
- }
- return _GridSource;
- }
- }
- public DataTable GridSourceSub(Guid regionid,DateTime dstart,DateTime dend,string deptsql)
- {
- return CalcCaseInfoByDeptReportLogic.GetDataTableByParms(regionid, dstart, dend, deptsql);
- }
- /// <summary>
- /// 加入小计
- /// </summary>
- /// <param name="dt"></param>
- /// <returns></returns>
- protected DataTable AddTableSmallSum(DataTable dt)
- {
- DataRow dr = dt.NewRow();
- dr[1] = "合计";
- for (int i = 2; i < dt.Columns.Count; i++)
- {
- int sum = 0;
- for (int j = 0; j < dt.Rows.Count; j++)
- {
- sum = sum + int.Parse(dt.Rows[j][i].ToString());
- }
- dr[i] = sum;
- }
- dt.Rows.Add(dr);
- return dt;
- }
- private void UltraWebGrid1_DemandLoad(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)
- {
- UltraGridBand band = UltraWebGrid1.Bands[e.Row.Band.Index + 1];
- if (band.Columns.Count == 0)
- {
- band.Columns.Add(new UltraGridColumn());
- band.Columns.Add(new UltraGridColumn());
- band.Columns.Add(new UltraGridColumn());
- band.Columns.Add(new UltraGridColumn());
- band.Columns.Add(new UltraGridColumn());
- band.Columns.Add(new UltraGridColumn());
- band.Columns.Add(new UltraGridColumn());
- band.Columns.Add(new UltraGridColumn());
- band.Columns[0].HeaderText = "region_id";
- band.Columns[0].Hidden = true;
- band.Columns[1].HeaderText = "部门";
- band.Columns[2].HeaderText = "受理数";
- band.Columns[3].HeaderText = "立案数";
- band.Columns[4].HeaderText = "结案数";
- band.Columns[5].HeaderText = "不予立案数";
- band.Columns[6].HeaderText = "移交数";
- band.Columns[7].HeaderText = "撤销中止数";
- }
- Guid regionid = new Guid(e.Row.Cells[0].Value.ToString());
- DataTable dt = this.GridSourceSub(regionid,new DateTime(),new DateTime(),this.DeptSQL);
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- e.Row.Rows.Add(new UltraGridRow());
- e.Row.Rows[i].Cells[0].Value = dt.Rows[i]["region_id"];
- e.Row.Rows[i].Cells[1].Value = dt.Rows[i]["dept_name"];
- e.Row.Rows[i].Cells[2].Value = dt.Rows[i]["acceptcount"];
- e.Row.Rows[i].Cells[3].Value = dt.Rows[i]["basiccount"];
- e.Row.Rows[i].Cells[4].Value = dt.Rows[i]["endcount"];
- e.Row.Rows[i].Cells[5].Value = dt.Rows[i]["nocreatecount"];
- e.Row.Rows[i].Cells[6].Value = dt.Rows[i]["movecount"];
- e.Row.Rows[i].Cells[7].Value = dt.Rows[i]["stopcount"];
- e.Row.Rows[i].ShowExpand = true;
- }
- if (UltraWebGrid1.Bands[band.Index + 1] == null)
- UltraWebGrid1.Bands.Add(new UltraGridBand());
- }
- private void UltraWebGrid1_InitializeLayout(object sender, Infragistics.WebUI.UltraWebGrid.LayoutEventArgs e)
- {
- UltraWebGrid1.DisplayLayout.RowSelectorStyleDefault.Width = Unit.Pixel(350);
- }
- private void BindView()
- {
- UltraWebGrid1.ResetRows();
- for (int i = 0; i < GridSource.Rows.Count; i++)
- {
- UltraWebGrid1.Rows.Add(new UltraGridRow());
- UltraWebGrid1.Rows[i].Cells[0].Value = GridSource.Rows[i]["region_id"];
- UltraWebGrid1.Rows[i].Cells[1].Value = GridSource.Rows[i]["dept_name"];
- UltraWebGrid1.Rows[i].Cells[2].Value = GridSource.Rows[i]["acceptcount"];
- UltraWebGrid1.Rows[i].Cells[3].Value = GridSource.Rows[i]["basiccount"];
- UltraWebGrid1.Rows[i].Cells[4].Value = GridSource.Rows[i]["endcount"];
- UltraWebGrid1.Rows[i].Cells[5].Value = GridSource.Rows[i]["nocreatecount"];
- UltraWebGrid1.Rows[i].Cells[6].Value = GridSource.Rows[i]["movecount"];
- UltraWebGrid1.Rows[i].Cells[7].Value = GridSource.Rows[i]["stopcount"];
- }
- UltraWebGrid1.Bands.Add(new UltraGridBand());
- for (int i = 0; i < UltraWebGrid1.Rows.Count - 1; i++)
- {
- UltraWebGrid1.Rows[i].ShowExpand = true;
- }
- }
- protected void BtnToExcel_Click(object sender, EventArgs e)
- {
- //UltraWebGridExcelExporter export = new UltraWebGridExcelExporter("GRIDDATAOUTPUT");
- //export.Export(this.UltraWebGrid1);
- this.UltraWebGridExcelExporter1.WorksheetName = "GRIDDATAOUTPUT";
- UltraWebGridExcelExporter1.Export(this.UltraWebGrid1);
- //Dictionary<string, string> columns = new Dictionary<string, string>();
- //columns.Add("region_name", "案件类别");
- //columns.Add("acceptcount", "受理数");
- //columns.Add("basiccount", "立案数");
- //columns.Add("endcount", "结案数");
- //columns.Add("nocreatecount", "不予立案数");
- //columns.Add("movecount", "移交数");
- //columns.Add("stopcount", "撤销中止数");
- columns.Add("smallsum", "合计");
- ExcelHelper.ToExcel(GridSource, "test.xls", columns);
- //string filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
- //XLSHelper.CreateFile(GridSource, columns, Server.MapPath("../xls/" + filename));
- //Response.Redirect("../xls/" + filename);
- }
- protected void btnToOfficeExcel_Click(object sender, EventArgs e)
- {
- Session["datasource"] = this.GridSource;
- string url = "..//../iWebOffice2006/DocumentEditOffice.aspx?FileType=.xls";// 打印excel
- Response.Write("<script>window.open('" + url + "','newwindow','toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no');</script>");
- }
- }
- }
在后台代码中的
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.UltraWebGrid1.DemandLoad += new Infragistics.WebUI.UltraWebGrid.DemandLoadEventHandler(this.UltraWebGrid1_DemandLoad);
- this.UltraWebGrid1.InitializeLayout += new Infragistics.WebUI.UltraWebGrid.InitializeLayoutEventHandler(this.UltraWebGrid1_InitializeLayout);
- }
是必须的.
GridSource是我们读取的数据源.
UltraWebGrid1_DemandLoad事件用于点击下级时触发的.
还有我的代码中还到toExcel的
也是UltraWebGridExcelExporter1 导出层级关第的.
关键点:
我的绑定数据的时候只能一个一个分开来绑定,
不能使用
UltraWebGrid1.DataBind();这样不能出分层按键.