954,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

If Datasource=null, how to show gridview with header

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

arunmozhi
Newbie Poster
6 posts since Dec 2008
Reputation Points: 10
Solved Threads: 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;
        }
Aneesh_Argent
Junior Poster
104 posts since Dec 2008
Reputation Points: 16
Solved Threads: 18
 

please mark as solved if this solved your problem.

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You