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..

Recommended Answers

All 2 Replies

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;
        }

please mark as solved if this solved your problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.