asp.net in the DataGrid double row cross column cross row complex table head design experience!

Source: Internet
Author: User
asp.net|datagrid| Design | experience
property settings for a DataGrid
1. Allowpaging:true
2. Pagestyle->position:topandbottom
3. Optional: Pagestyle->horizonalign:center (make text centered)
4. Optional: Itemstyle->horizonalign:center (make text centered)
Second, the Code section
1. First, make the DataGrid bind to a table in the database, for example:
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
if (! IsPostBack)
{
SqlConnection myconn=new SqlConnection ("Server=localhost;uid=sa;pwd=sa;database=db_test");
SqlDataAdapter Da=new SqlDataAdapter ("select * from individual", myconn);
DataSet ds=new DataSet ();
Da. Fill (ds, "gr");
Dggeren.datasource=ds. Tables["GR"]. DefaultView;
Dggeren.databind ();


}
2. Add the handler function for the ItemCreated event for the DataGrid,
3. In order to determine the position of the two (up and down) pager in the DataGrid, we can use a global variable to determine.
Define a global variable private int m_createpagetimes = 0;
4. Add content to the handler function for the ItemCreated event of the DataGrid, as follows:
private void Dggeren_itemcreated (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Switch (e.item.itemtype)
{
Case (Listitemtype.pager):
Case Listitemtype.pager:
{
if (m_createpagetimes = 0)
{
DataGridItem row= (DataGridItem) E.item;
Row. Cells.clear ();

Row.  Backcolor=color.navy; Background color
Row. forecolor=color.red; Foreground color

Row. horizontalalign=horizontalalign.center;//Text to the center

TableCell cell0=new TableCell ();
Cell0. rowspan=2;
Cell0. Controls.Add (New LiteralControl ("name"));

TableCell cell1=new TableCell ();
Cell1.   columnspan=2; The default ColumnSpan value is 1
Cell1. text= "Housing address information";

It could be: cell1. Controls.Add (New LiteralControl ("Housing Address Information"));

TableCell cell2=new TableCell ();
Cell2. Controls.Add (New LiteralControl (""));
TableCell cell2=new TableCell ();
Cell2. rowspan=2;
Cell2. text= "date of birth";

Row. Cells.add (cell0);
Row. Cells.add (CELL1);
Row. Cells.add (CELL2);


m_createpagetimes++;
}
Break
}
Case Listitemtype.header:
{
DataGridItem head= (DataGridItem) E.item;
Head. Cells.clear ();

Head. Verticalalign=verticalalign.middle;
Head. Horizontalalign=horizontalalign.center;

TableCell cell00=new TableCell ();
Cell00. rowspan=2;
Cell00. text= "Name";

TableCell cell01=new TableCell ();
Cell01. text= "floor number";

TableCell cell02=new TableCell ();
Cell02. text= "Room number";

TableCell cell03=new TableCell ();
Cell03. text= "date of birth";

Head. Cells.add (cell00);
Head. Cells.add (CELL01);
Head. Cells.add (CELL02);
Head. Cells.add (CELL03);
Break
}



}

}

Third, the final effect of the following figure:

Four, hope everyone to guide!


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.