0

in asp.net how to show the girdview with header, when the datasource=null, i have used

gridview.EmptyDataText="Some Text"

but i need to show the grid with the header

any one plz help me..

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by serkan sendur
0

Before binding your DataTable(DataSource) to the grid, check the row count of the DataTable. If its empty (row count = 0) then add a dummy row to the DataTable and then bind it with the grid. Also make the visibility of the dummy row in the grid to false.

Here is some sample code

if(dt.Rows.Count > 0 )
        {
            //DataSource is not empty
            gvResults.DataSource = dt;
            gvResults.DataBind();
        }
        else
        {
            //DataSource empty, add dummy row
            dt.Rows.Add(dt.NewRow());
            gvResults.DataSource = dt;
            gvResults.DataBind();
           //Make dummy row invisible
            gvResults.Rows[0].Visible = false;
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.