how to add the footer row dynamically in gridview. with textboxes.. pls give any idea...
Hi. please Follow the Steps
1.Assign DataSource to Gridview
2.In RowDataBound Find the GridView's RowType
3. If RowType is FooterRow
4.Dynamically Add Textbox or Desired Control in the Row (Every row is rendor as TableRow)
you can customize it.
Since there can be only one footer row in the grid view IMO it is better to add the footer row by setting the ShowFooter
property of the grid view to true
. Setting the
FooterStyle
property can be helpful here.
When coming to the programming part,
protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
TextBox txt = new TextBox();
// set properties of text box
e.Row.Cells[0].Controls.Add(txt);
}
}
Try this and comment.
Edit : This will be helpful http://www.asp.net/data-access/tutorials/displaying-summary-information-in-the-gridview-s-footer-cs
There is only one footer row so you can control if it is displayed dynamically in code as follows:
if (GridView.EditIndex == -1)
GridViewProject.FooterRow.Visible = true;
}
else
{
GridViewProject.FooterRow.Visible = false;
}
In the RowDataBound event check the row type and set any defaults needed there: I find it useful to acutally use dropdown lists wherever possible to keep the user from entering bad data
switch (e.Row.RowType)
{
case DataControlRowType.Header:
case DataControlRowType.DataRow:
case DataControlRowType.Footer:
//popluate ddls
}