just wanted to know what is the best and easiest way to show a gridview footer for data entry even when the gridview is empty ?
As a side-note, if you want to conditionally EITHER show the grid's header and footer OR show the emptydata text/template, after you have hidden the row with the code I posted above, you can check your condition and if necessary delete the row. Then the code will look something like this:
Protected Sub MyGridView_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles MyGridView.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) AndAlso (Not e.Row.DataItem Is Nothing) AndAlso (CInt(e.Row.DataItem("dummyRow")) = 1) Then
e.Row.Visible = False
If (ConditionToShowEmptyDataTemplate) Then
CType(e.Row.DataItem, System.Data.DataRowView).Delete()
CType(e.Row.Parent, System.Web.UI.WebControls.Table).Rows.Remove(e.Row)
End If
End Sub
Notice that here we remove both the DataItem row (necessary because on post-backs the gridview may redraw itself without re-databinding) and the GridView Row itself (necessary because by this point the row is already in the grid's Childtable, which we don't want).
Finally, if the hidden dummy record is causing other issues in your gridview when it has other data (for example, bad paging), you can use similar code to delete your dummy row when the gridview has more rows.