If Datasource=null, how to show gridview with header

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 6
Reputation: arunmozhi is an unknown quantity at this point 
Solved Threads: 0
arunmozhi arunmozhi is offline Offline
Newbie Poster

If Datasource=null, how to show gridview with header

 
0
  #1
Mar 4th, 2009
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..
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

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

 
0
  #2
Mar 4th, 2009
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
  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. }
Falling down is not defeat...
Defeat is when you refuse to getup...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 120
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

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

 
0
  #3
Mar 4th, 2009
please mark as solved if this solved your problem.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC