Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Empty DataSet and GridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 21 Aug 2007 12:50 GMT
Hello,

Is it possible to display a message in a GridView such as "No Records
Available" when the DataSet is empty?

Thanks,

Miguel
Ladislav Mrnka - 21 Aug 2007 13:06 GMT
Hi Miguel,
GridView contains EmptyDataTemplate which is used in your case.

Regards,
Ladislav

> Hello,
>
[quoted text clipped - 4 lines]
>
> Miguel
Mike - 21 Aug 2007 13:21 GMT
or you could just not show the grid and show a message in its place if your
ds is empty.

something like
if(ds.row.count > 0)
{
     show grid
}
else
{
         show no records found message
}

> Hello,
>
[quoted text clipped - 4 lines]
>
> Miguel
shapper - 21 Aug 2007 15:40 GMT
> or you could just not show the grid and show a message in its place if your
> ds is empty.
[quoted text clipped - 18 lines]
>
> > Miguel

Hi,

I need o create it at runtime and I am having a few problems. On my
GridView ITemplate I have the following:

     Dim edtPost As New TemplateField
     edtPost.ItemTemplate = New edtPost(ListItemType.Item)
     gvPosts.EmptyDataTemplate = edtPost

edtPost is a class as follows:

   ' edtPost
   Private Class edtPost
     Implements ITemplate

     Private Type As ListItemType

     Public Sub New(ByVal type As ListItemType)
       Me.Type = type
     End Sub ' New

     Public Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn

       ' Select template type
       Select Case Me.Type

         Case ListItemType.Item                    ' Item template

           Dim l As New Label
           l.Text = "No Records Found"
           container.Controls.Add(l)

       End Select

     End Sub ' InstantiateIn

   End Class ' edtPost

I am getting the error:

Unable to cast object of type
'System.Web.UI.WebControls.TemplateField' to type
'System.Web.UI.ITemplate'.

On code line:

gvPosts.EmptyDataTemplate = edtPost

How can I solve this?

Thanks,

Miguel
weston.jossey@gmail.com - 21 Aug 2007 13:25 GMT
> Hello,
>
[quoted text clipped - 4 lines]
>
> Miguel

You can also, if you would prefer the columns and grids did not
display as there is no data, to read the property Rows from the
GridView, and if (rows == 0) then alertLabel.Visible = true;
alertLabel.Text = "Blah blah"

Where an alertLabel is merely an invisible label you hide in your
screen to display only upon empty resultant sets.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.