Double header in datagrid
-
Is it Possible to have 2 header rows(header for header)for a scrolling datagrid with fixed header.Plz Help. Thanks in advance. -- modified at 3:10 Thursday 20th April, 2006
Check out this solution: http://forums.asp.net/390809/ShowPost.aspx[^] Here is the C# Equivalent (with some added stuff I did to help those with possible questions): private void DataGrid1_PreRender(object sender, System.EventArgs e) { //This MUST be done in the Pre-Render function. Otherwise will have errors if running this code outside of the PreRender function. DataGridItem dgItem = new DataGridItem(0,0,ListItemType.Header); TableCell myCell = new TableCell(); myCell.ColumnSpan = 2; //This Merges Cells together. myCell.Text = "Test"; myCell.BackColor = Color.Lavender; //Change the back color of a single cell. myCell.VerticalAlign = VerticalAlign.Middle;//This Centers the text vertically for a single cell. dgItem.Cells.Add(myCell); dgItem.HorizontalAlign = HorizontalAlign.Center;//This centers the text for the entire dgItem (which in this case is the additional header we just added). DataGrid1.Columns[1].HeaderStyle.BackColor = Color.LemonChiffon;//This changes the color for an entire column, not needed, but is neat to see if you were thinking about doing something like this in the future - now you know how to. DataGrid1.Controls[0].Controls.AddAt(0, dgItem); //Change the integer in the AddAt() function to insert the header somewhere else in the datagrid (like 1 for below the original header, or 5 if for some inexplicable reason you want two totally separated headers with rows of data in between them. } Hope you guys liked it! Big Thanks to Jim Ross and his post at forums.ASP.Net website and his source who gave him the original VB code: Anand Hegde (MSFT). - M