JeffDrummond
asked on
Insert row in header of ASP.Net datagrid
Hello:
I am developing a report that uses a datagrid with about 15 columns.
The area of the report above the last two column headings contains
some special instructions about those two columns.
Can I add a row to the datagrid header above the row that
has all the column headings? If that is possible I think I will
be able to do some formatiing of the last two headers programatically.
Thanks!
I am developing a report that uses a datagrid with about 15 columns.
The area of the report above the last two column headings contains
some special instructions about those two columns.
Can I add a row to the datagrid header above the row that
has all the column headings? If that is possible I think I will
be able to do some formatiing of the last two headers programatically.
Thanks!
Hi,
In addition of vardium you can access the header control from the codebehind like here :
http://www.howtodothings.com/showarticle.asp?article=695
Regards,
B..M
In addition of vardium you can access the header control from the codebehind like here :
http://www.howtodothings.com/showarticle.asp?article=695
Regards,
B..M
ASKER
Thanks Vardium, but development is too far along to switch controls now.
Regarding the article, I don't understand how to add a row to the datagrid
header using the example given. I see how you can get to the controls
in the header, but adding a row?
I'm trying this in the datagrid ItemDataBound event:
If e.Item.ItemType = ListItemType.Header Then
Dim header As Control = CType(sender, DataGrid).Controls(0).Cont rols(0)
==>> What next?
End If
Thanks! I appreciate your help.
Regarding the article, I don't understand how to add a row to the datagrid
header using the example given. I see how you can get to the controls
in the header, but adding a row?
I'm trying this in the datagrid ItemDataBound event:
If e.Item.ItemType = ListItemType.Header Then
Dim header As Control = CType(sender, DataGrid).Controls(0).Cont
==>> What next?
End If
Thanks! I appreciate your help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Say the datagrid header contains the following columns:
__________________________ ______
Author | Title | Date |
-------------------------- ---------- ---------
I want to add a row to the header above the column titles:
__________________________ ______
___________|________|_____ ______|
Author | Title | Date |
-------------------------- ---------- ---------
I've been working with your example above but I do not
know enough to get it to work.
Thanks.
__________________________
Author | Title | Date |
--------------------------
I want to add a row to the header above the column titles:
__________________________
___________|________|_____
Author | Title | Date |
--------------------------
I've been working with your example above but I do not
know enough to get it to work.
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I got this working with a slight addition to ipmcc's code as follows:
private void grdSchedule_ItemCreated(ob ject sender, System.Web.UI.WebControls. DataGridIt emEventArg s e)
{
if (e.Item.ItemType == ListItemType.Header)
{
// make a new item that you want to insert -- it must be a datagrid item -- its joining
// the existin header, so set it with all the same params
DataGridItem myItem = new DataGridItem(e.Item.ItemIn dex, e.Item.DataSetIndex, e.Item.ItemType);
foreach (TableCell cell in e.Item.Cells)
{
myItem.Cells.Add(new TableCell());
}
foreach (TableCell cell in myItem.Cells)
{
cell.Text = "AAA";
}
// add various, hopefully useful stuff to your new row here...
((DataGrid)sender).Control s[0].Contr ols.Add(my Item);
}
}
I want some of my top cells to span mroe than one column though which I'm looking at now. I'll come back if I figure out how to do it.
Dave
private void grdSchedule_ItemCreated(ob
{
if (e.Item.ItemType == ListItemType.Header)
{
// make a new item that you want to insert -- it must be a datagrid item -- its joining
// the existin header, so set it with all the same params
DataGridItem myItem = new DataGridItem(e.Item.ItemIn
foreach (TableCell cell in e.Item.Cells)
{
myItem.Cells.Add(new TableCell());
}
foreach (TableCell cell in myItem.Cells)
{
cell.Text = "AAA";
}
// add various, hopefully useful stuff to your new row here...
((DataGrid)sender).Control
}
}
I want some of my top cells to span mroe than one column though which I'm looking at now. I'll come back if I figure out how to do it.
Dave
Ok figured this out.
You can set the columnspan property as follows:
foreach (TableCell cell in myItem.Cells)
{
cell.Text = "AAA";
cell.ColumnSpan = 2;
}
Which means thet the code which originally inserts the cells must change to insert less cells as appropriate. For example use:
for (int i=0; i < 10; i ++)
{
myItem.Cells.Add(new TableCell());
}
But change the 10 to match your requirements
Dave
You can set the columnspan property as follows:
foreach (TableCell cell in myItem.Cells)
{
cell.Text = "AAA";
cell.ColumnSpan = 2;
}
Which means thet the code which originally inserts the cells must change to insert less cells as appropriate. For example use:
for (int i=0; i < 10; i ++)
{
myItem.Cells.Add(new TableCell());
}
But change the 10 to match your requirements
Dave
by this way you can put as many rows as you wish in the <headertemplate> of the repeater.