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}
],