Add custome footer in gridview with colspan properties in center

Rajni.Shekhar
Posted by Rajni.Shekhar under ASP.NET category on | Points: 40 | Views : 3631
protected void grdPaymentDtls_RowCreated(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType.Equals(DataControlRowType.Footer))
{
//Build custom footer.
GridView objGV = (GridView)sender;
GridViewRow objGVRow = new GridViewRow(0, 0,
DataControlRowType.Footer, DataControlRowState.Insert);

//create instance of tablecell for gv
TableCell objGVCell = new TableCell();

//create instance of table/table row/table cell
Table tb = new Table();
TableRow tr = new TableRow();
TableCell tc = new TableCell();

//cell1
tc.Text = "Total Count:";
tc.CssClass = "label";
tc.Width = Unit.Percentage(25);
tc.Font.Bold = true;
tr.Cells.Add(tc);

//create label to add in cell2
Label lblTotCount = new Label();
lblTotCount.ID = "lblTotCount";
lblTotCount.Text = "";

//cell2
tc = new TableCell();
tc.Width = Unit.Percentage(25);
tc.Controls.Add(lblTotCount);
tr.Cells.Add(tc);

//cell3
tc = new TableCell();
tc.Text = "Total Amount:";
tc.CssClass = "label";
tc.Font.Bold = true;
tc.Width = Unit.Percentage(25);
tr.Cells.Add(tc);

//create label to add in cell4
Label lblTotAmt = new Label();
lblTotAmt.ID = "lblTotAmt";
lblTotAmt.Text = "";

//cell4
tc = new TableCell();
tc.Width = Unit.Percentage(25);
tc.Controls.Add(lblTotAmt);
tr.Cells.Add(tc);

//add row in table
tb.Rows.Add(tr);

//set gv cell and add table in gv cell
objGVCell.HorizontalAlign = HorizontalAlign.Center;
objGVCell.ColumnSpan = objGV.Columns.Count;
objGVCell.Controls.Add(tb);

//add gv cell in gvrow and gvrow in gv
objGVRow.Cells.Add(objGVCell);
objGV.Controls[0].Controls.AddAt(objGV.Rows.Count + 1, objGVRow);
}
}

Comments or Responses

Login to post response