943,692 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 5679
  • ASP.NET RSS
Mar 4th, 2009
0

If Datasource=null, how to show gridview with header

Expand Post »
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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
arunmozhi is offline Offline
6 posts
since Dec 2008
Mar 4th, 2009
0

Re: If Datasource=null, how to show gridview with header

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
ASP.NET Syntax (Toggle Plain Text)
  1. if(dt.Rows.Count > 0 )
  2. {
  3. //DataSource is not empty
  4. gvResults.DataSource = dt;
  5. gvResults.DataBind();
  6. }
  7. else
  8. {
  9. //DataSource empty, add dummy row
  10. dt.Rows.Add(dt.NewRow());
  11. gvResults.DataSource = dt;
  12. gvResults.DataBind();
  13. //Make dummy row invisible
  14. gvResults.Rows[0].Visible = false;
  15. }
Reputation Points: 16
Solved Threads: 18
Junior Poster
Aneesh_Argent is offline Offline
104 posts
since Dec 2008
Mar 4th, 2009
0

Re: If Datasource=null, how to show gridview with header

please mark as solved if this solved your problem.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Problem in updating date field in a table row
Next Thread in ASP.NET Forum Timeline: need a code to open a exe file in asp





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC