How remove empty row of header from Datagrid
I have create a datagrid. In the datagrid have merge column for header.so i have use Itemcreated events from datagrid. But problem is that,
it is created another/extra rows which I don't need. So how remove this rows
e.g.Heading of datagrid
-----------------------------------------------------
toll Plaza | total collection |
-------------------------------------------
| amount A | Amount B| total amount|
-----------------------------------------------------
| | | |
-----------------------------------------------------
code :
protected void dgTollData_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
try
{
if (e.Item.ItemType == ListItemType.Header)
{
DataGridItem dgItem = default(DataGridItem);
TableCell dgCell = new TableCell();
dgItem = new DataGridItem(0, 0, ListItemType.Header);
dgCell = new TableCell();
dgCell.RowSpan = 2;
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgCell.VerticalAlign = VerticalAlign.Middle;
dgItem.Cells.Add(dgCell);
dgCell.Text = "Toll Plaza";
dgCell = new TableCell();
dgCell.RowSpan = 2;
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgCell.VerticalAlign = VerticalAlign.Middle;
dgItem.Cells.Add(dgCell);
dgCell.Text = "From Date";
dgCell = new TableCell();
dgCell.RowSpan = 2;
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgCell.VerticalAlign = VerticalAlign.Middle;
dgItem.Cells.Add(dgCell);
dgCell.Text = "Total Traffic";
dgCell = new TableCell();
dgCell.RowSpan = 2;
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgCell.VerticalAlign = VerticalAlign.Middle;
dgItem.Cells.Add(dgCell);
dgCell.Text = "Total Exempted";
dgCell = new TableCell();
dgCell.ColumnSpan = 6;
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgCell.VerticalAlign = VerticalAlign.Middle;
dgItem.Cells.Add(dgCell);
dgCell.Text = "Total Non-Exempted";
this.dgTollData.Controls[0].Controls.AddAt(0, dgItem);
dgItem = new DataGridItem(0, 1, ListItemType.Header);
dgCell = new TableCell();
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgItem.Cells.Add(dgCell);
dgCell.Text = "LMV (Car,Jeep)";
dgCell = new TableCell();
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgItem.Cells.Add(dgCell);
dgCell.Text = "LCV (Mini Bus/Tempo)";
dgCell = new TableCell();
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgItem.Cells.Add(dgCell);
dgCell.Text = "Bus/Truck";
dgCell = new TableCell();
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgItem.Cells.Add(dgCell);
dgCell.Text = "3 Axle Vehicle";
dgCell = new TableCell();
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgItem.Cells.Add(dgCell);
dgCell.Text = "Oversie Vehicles";
dgCell = new TableCell();
dgCell.HorizontalAlign = HorizontalAlign.Center;
dgItem.Cells.Add(dgCell);
dgCell.Text = "Total";
this.dgTollData.Controls[0].Controls.AddAt(1, dgItem);
}
//for group of items
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (createsub)
{
DataGrid dg = (DataGrid)sender;
TableCell tc = new TableCell();
tc.Controls.Add(new LiteralControl(subheading));
tc.ColumnSpan = 11;
tc.Attributes.Add("align", "left");
tc.Font.Bold = true;
tc.BackColor = ColorTranslator.FromHtml("#F08080");
tc.ForeColor = Color.White;
DataGridItem di = new DataGridItem(e.Item.ItemIndex + 1, 0, ListItemType.Item);
di.Cells.Add(tc);
Table t = (Table)dg.Controls[0];
t.Rows.Add(di);
}
}
}
catch (Exception ex)
{
throw ex;
}
}