The datagrid specifies the combination and export of rows, and the datagrid specifies the Export

Source: Internet
Author: User

The datagrid specifies the combination and export of rows, and the datagrid specifies the Export

Export Code:

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

Override method. This method must be:

Public override void VerifyRenderingInServerForm (Control control Control)
{

}

Merge columns:

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

 

// Merge
Public static void GroupRows (GridView GridView1, int [] cellIndex, int mostlyid)
{
Int I = 0, rowSpanNum = 1;
While (I <GridView1.Rows. Count-1)
{
GridViewRow gvr = GridView1.Rows [I];
For (++ I; I <GridView1.Rows. Count; I ++)
{
GridViewRow gvrNext = GridView1.Rows [I];
If (gvr. cells [cellIndex [mostlyid]. text = gvrNext. cells [cellIndex [mostlyid]. text) // & gvr. cells [cellIndex [mostlyid]. text = gvrNext. cells [cellIndex [mostlyid]. text)
{
GvrNext. Cells [cellIndex [mostlyid]. Visible = false; // otherwise, other operations will be squeezed out, resulting in row highlighting.
RowSpanNum ++;
}
Else
{
Gvr. Cells [cellIndex [mostlyid]. RowSpan = rowSpanNum;
RowSpanNum = 1;
Break;
}
If (I = GridView1.Rows. Count-1)
{
Gvr. Cells [cellIndex [mostlyid]. RowSpan = rowSpanNum;
}
}
}
}


C # How to export an EXCEL worksheet after the datagridview merges rows

Exporting data from a datatable is not affected by the grid format.

How to merge two or three rows in a column in the jquery easyui datagrid

FrozenColumns :[[
{Field: 'ck ', checkbox: true },
{Title: 'code', field: 'code', width: 80, sortable: true}
],
Columns :[[
{Title: 'base information', colspan: 3 },
{Field: 'opt', title: 'operation', width: 100, align: 'center', rowspan: 2}
], [
{Field: 'name', title: 'name', width: 120 },
{Field: 'addr ', title: 'address', width: 220, rowspan: 2, sortable: true },
{Field: 'col4', title: 'col41', width: 150, rowspan: 2}
],

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.