The easiest way to do this is to associate an array with a length of one. You can put something in this, you like to identify that it is a dummy string. In the GridViews RowDataBound method, check if the data item is a dummy string (make sure the RowType is a DataRow first before trying to validate the data). If it is a dummy line, set the line visibility to false. The footer and header should now display without any data.
Make sure the ShowFooter property is set to true in 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;
}
}
}
source
share