DataGrid multi-dimensional table header, cross-row and cross-column header design, multi-dimensional datagrid
The dataGrid is actually an html table.
After thinking about this, it is easy to set the multi-dimensional header.
HTML code <asp: DataGrid ID = "DataGrid1" runat = "server" onitemdatabound = "DataGrid1_ItemDataBound"> </asp: DataGrid> then bind the data 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 ();} Add the DataGrid1_ItemDataBoun event 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> <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 ;}}