DataGrid multidimensional table header, header cross row Cross column design and binding data _ practical Tips

Source: Internet
Author: User
The DataGrid is actually an HTML table
When you think about it, it's a good idea to set up a multidimensional table header.
HTML code
Copy Code code as follows:

<asp:datagrid id= "DATAGRID1" runat= "Server"
onitemdatabound= "Datagrid1_itemdatabound" >
</asp:DataGrid>

And then bind the data
Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
String strSQL = "Select EmpID, Name, Branchid, loginID, PWD, Sex, Empcode, Email, Officetel from Mrbaseinf";
SqlConnection con = new SqlConnection ("server=.; Database=ioffice2009;uid=sa;pwd=sa ");
DataSet ds = new DataSet ();
SqlDataAdapter ter = new SqlDataAdapter (strSQL, con);
Con. Open ();
ter. Fill (DS);
Con. Close ();
This. DataGrid1.DataSource = ds;
Datagrid1.databind ();
}

Next Add Datagrid1_itemdataboun Event
Copy Code code as follows:

protected void Datagrid1_itemdatabound (object sender, DataGridItemEventArgs e)
{
if (E.item.itemtype==listitemtype.header)
{
E.item.cells[0]. RowSpan = 2;
E.ITEM.CELLS[1]. RowSpan = 2;
E.ITEM.CELLS[2]. RowSpan = 2;
E.ITEM.CELLS[3]. RowSpan = 2;
E.ITEM.CELLS[4]. RowSpan = 2;
E.ITEM.CELLS[5]. ColumnSpan = 4;
E.ITEM.CELLS[5]. HorizontalAlign = Horizontalalign.center;
E.ITEM.CELLS[5]. Text = "Test </td></tr><tr><td> column 1</td><td> column 2</td><td> column 3</td> <td> column 4</td></tr> ";
E.ITEM.CELLS[6]. Visible = false;
E.ITEM.CELLS[7]. Visible = false;
E.ITEM.CELLS[8]. Visible = false;
}
}

Effect chart

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.