datagrid指定行合并导出
导出代码:
public void GridViewToExcel(GridView ctrl, string FileType, string FileName)
{
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
HttpContext.Current.Response.ContentType = FileType;//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
ctrl.Page.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctrl.AllowPaging = false;
bind();
ctrl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
ctrl.AllowPaging = true;
bind();
}
重写方法,此方法必须需要:
public override void VerifyRenderingInServerForm(Control control)
{
}
指定合并列:
protected void GridView1_DataBound(object sender, EventArgs e)
{
int[] arr = new int[] { 1,3,5 };
GroupRows(GridView1, arr, 2);
GroupRows(GridView1, arr, 0);
GroupRows(GridView1, arr, 1);
}