943,600 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 38028
  • ASP.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 9th, 2007
0

Gridview display for an empty dataset

Expand Post »
Hi Everybody

How can i display in the gridview.
"there is no data for this request" if the binded dataset is empty?

Can anyone give some ideas?

Thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Feb 9th, 2007
0

Re: Gridview display for an empty dataset

why not check whether the DataSet has any rows in code before binding then show/hide a label with that text?
Reputation Points: 68
Solved Threads: 9
Junior Poster
sedgey is offline Offline
130 posts
since Jan 2007
Feb 9th, 2007
0

Re: Gridview display for an empty dataset

alternatively if it must appear in the grid view, why not build a data table with one column called result and add a row who's value is your text, then bind it to your grid view
Reputation Points: 68
Solved Threads: 9
Junior Poster
sedgey is offline Offline
130 posts
since Jan 2007
Feb 12th, 2007
0

Re: Gridview display for an empty dataset

Thanks
First one seems to be more easy
I will try for that
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Feb 12th, 2007
1

Re: Gridview display for an empty dataset

GridView supports EmptyDataRowStyle

http://msdn2.microsoft.com/en-us/lib...arowstyle.aspx
Reputation Points: 13
Solved Threads: 4
Junior Poster in Training
nikkiH is offline Offline
79 posts
since Dec 2006
Feb 12th, 2007
0

Re: Gridview display for an empty dataset

spot on nikkiH
Reputation Points: 68
Solved Threads: 9
Junior Poster
sedgey is offline Offline
130 posts
since Jan 2007
May 25th, 2009
0

Re: Gridview display for an empty dataset

If there is No Data in Gridview and we want to show a message that “No data available”.
We can do this by using the following tag in gridview.

ASP.NET Syntax (Toggle Plain Text)
  1. <EmptyDataTemplate>
  2.  
  3. No Data Available
  4.  
  5. </EmptyDataTemplate>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
znetweb is offline Offline
17 posts
since May 2008
May 26th, 2009
0

Re: Gridview display for an empty dataset

JUST ADD THE EmptyDataText PROPERTY IN THE FOLLOWING WAY:
ASP.NET Syntax (Toggle Plain Text)
  1. <asp:GridView runat="server" ID="gvCaseDetail" Width="100%"
  2. EmptyDataText="there is no data for this request"
  3. ......................................

YOU CAN ALSO RENDER HTMEL TEXT LIKE:
ASP.NET Syntax (Toggle Plain Text)
  1. <asp:GridView runat="server" ID="gvCaseDetail" Width="100%"
  2. EmptyDataText="<table cellspacing=1 cellpadding=4 rules=rows border=0 style=color:Black;font-family:Tahoma;font-size:1em;width:730px;border-collapse:collapse;><tr style=color:Black;background-color:#00BFFF;font-weight:bold;><th scope=col>Case ID</th><th align=center scope=col>Subject</th><th align=center scope=col>Status</th><th align=center scope=col>Date</th><th align=center scope=col>Action</th></tr></table>"
  3. ..............................

ONE THING YOU HAVE TO KEEP IN MIND THAT IF YOU DIDN'T BIND ANY DATASOURCE YOU WILL GET BLANK.
Reputation Points: 26
Solved Threads: 44
Posting Whiz in Training
mail2saion is offline Offline
247 posts
since Apr 2009
May 26th, 2009
0

Re: Gridview display for an empty dataset

Dear,

zneweb and mail2saion have solved your problem.

ASP.NET Syntax (Toggle Plain Text)
  1. <asp:GridView ID="GridView1" runat="server">
  2. <EmptyDataTemplate>
  3. There is no data.
  4. </EmptyDataTemplate>
  5. </asp:GridView>
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
May 26th, 2009
0

Re: Gridview display for an empty dataset

try with this. My english is poor ok?

ASP.NET Syntax (Toggle Plain Text)
  1. Public Sub CheckEmptyGrid(ByVal grid As WebControls.GridView)
  2.  
  3. If grid.Rows.Count = 0 And Not grid.DataSource Is Nothing Then
  4. Dim dt As Object = Nothing
  5. If grid.DataSource.GetType Is GetType(Data.DataSet) Then
  6. dt = New System.Data.DataSet
  7. dt = CType(grid.DataSource, System.Data.DataSet).Tables(0).Clone()
  8. ElseIf grid.DataSource.GetType Is GetType(Data.DataTable) Then
  9. dt = New System.Data.DataTable
  10. dt = CType(grid.DataSource, System.Data.DataTable).Clone()
  11. ElseIf grid.DataSource.GetType Is GetType(Data.DataView) Then
  12. dt = New System.Data.DataView
  13. dt = CType(grid.DataSource, System.Data.DataView).Table.Clone
  14. End If
  15. dt.Rows.Add(dt.NewRow())
  16. grid.DataSource = dt
  17. grid.DataBind()
  18. grid.Rows(0).Visible = False
  19. grid.Rows(0).Controls.Clear()
  20. End If
  21. End Sub

and the call

ASP.NET Syntax (Toggle Plain Text)
  1. CheckEmptyGrid(Grid)

With this the headers appers ok
Reputation Points: 10
Solved Threads: 0
Newbie Poster
argisoft is offline Offline
1 posts
since May 2009

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: Get images from database to Ajaxslideshow
Next Thread in ASP.NET Forum Timeline: DropDownList problem





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


Follow us on Twitter


© 2011 DaniWeb® LLC