views:

1000

answers:

2

how to show footer when there is no data in gridview for inserting data from footer.

A: 

The easiest way to do this is to bind an array with a length of one. You can put anything in it you like to identify that this is a dummy row. On your GridViews RowDataBound method check to see if the data item is the dummy row (make sure the RowType is a DataRow first before trying to check the data). If it is the dummy row set the rows visibility to false. The footer and header should now be showing without any data.

Make sure you set the ShowFooter property to true on your GridView.

eg.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostback)
    {
         myGrid.DataSource = new object[] {null};
         myGrid.DataBind();
    }
}    

protected void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.DataItem == null)
        {
             e.Row.Visible = false;
        }
    }
}
Mike737
This is not working when Autogenerate Columns == false, any other ideas ?
msbyuva
It should be as I've done it many times before. Have you made sure you have bound something to it on page load?
Mike737
A: 

Dears i was writing in my blog about this issue but for c# , you can review the post and check if it will be helpful or not ,

http://blog.waleedmohamed.net/2009/04/show-grid-view-header-and-footer-when.html

i was using a generic way with an helper to retrieve an empty list to fill the gird please check and if u have any quest don't hesitate to contact me or ask it on stack site

Waleed Mohamed
can we achieve this with out using Generics.. ?
msbyuva
you mean if u using dataset or datatable to fill your grid in this case i think you can use empty row to show the footer
Waleed Mohamed