Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 4th, 2003, 10:28 PM
Authorized User
 
Join Date: Jun 2003
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default counting records in a <asp:repeater>

Hi everyone,

Im still working around the new features of .net and have created a dataset and i use the repeater to dynamically create a table. It all works fine, but now i need some logic to not display the repeater if not records are found. How do findout how many records are found.

Thanks Tim

***CODE BELOW***

<script language="vb" runat="server">
Sub Page_Load
If Not Page.IsPostBack Then
Dim objConn, strSQL, DBComm, DBRead, TID, CollectionName, CollectionImageLarge
TID = Request.Form("TID")
ViewState("CollectionName") = Request.Form("CollectionName")
ViewState("CollectionImageLarge") = Request.Form("CollectionImageLarge")
objConn = New OledbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Inetpub\wwwroot\veroniqueparis\database\ VeroniqueParisDB.mdb")
objConn.Open()
strSQL = "SELECT * FROM tblTasselItems WHERE TasselCollectionID = " & TID & " ORDER BY TasselItemID"
    DBComm = New OleDbCommand(strSQL,objConn)
    DBRead = DBComm.ExecuteReader()
    tassel.DataSource = DBRead
    tassel.DataBind()
    DBRead.Close()
    objConn.Close()

End If
End Sub
</script>

*** Repeater Code ****

<asp:Repeater ID="tassel" runat="server">
<headertemplate>
<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#000000"><tr class="pageheaders">
<th width="15%" scope="col"><span class="style11">ITEM No. </span></th>
<th width="55%" scope="col"><span class="style11">Description</span></th>
<th width="15%" scope="col"><span class="style11">No. per pack </span></th>
<th width="15%" scope="col"><span class="style11">size</span></th>
</tr>

</headertemplate>
<itemtemplate>

<tr bgcolor="#FDFCF2">
<td width="15%"><span class="style19"><%# Container.DataItem"TasselItem") %></span></td>
<td width="52%"><span class="style19"><%# Container.DataItem("TasselDescription") %></span></td>
<td width="18%" align="center"><span class="style19"><%# Container.DataItem("TasselPack") %></span></td>
<td width="15%" align="center"><span class="style19"><%# Container.DataItem("TasselSize") %></span></td>
</tr>
</itemtemplate>
<footertemplate></table></footertemplate>
</asp:Repeater>

TDA
__________________
TDA
 
Old December 5th, 2003, 10:28 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Check the OleDbDataReader.HasRows property.
Set the repeater visibility based on that.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 5th, 2003, 03:05 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Alternatively (if you're using the .NET Framework version 1.0), you can check the Items collection of the Control you have bound your data to. Something like this should work:
Code:
// Bind Data Here
if (myDataGrid.Items.Count > 0)
{
  // There are Items
}
else
{
  // There are no Items
  // Display a Label, or whatever.
}
This has always worked for me, before HasRows was introduced.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 7th, 2003, 08:46 PM
Authorized User
 
Join Date: Jun 2003
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

Thanks guys,

All worked out well. I used the .Items.Count

Just for future interest how do you use the OleDbDataReader.HasRows property. I kept getting
'HasRows' is not a member of 'System.Data.OleDb.OleDbDataReader'.

Thanks again
Tim


TDA
 
Old December 8th, 2003, 02:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

HasRows was introduced in the .NET Framework version 1.1. Which version are you using?

Imar


(Edited this post. I said HasRows is available as of version 1.0, while I should have said 1.1)

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 8th, 2003, 04:29 AM
Authorized User
 
Join Date: Jun 2003
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

I am using
Version:1.0.3705.0

will this prevent the HasRows working? Could you show me a quick reference how you would use this property.

Thanks

TDA
 
Old December 8th, 2003, 04:49 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Right, I thought so. This is version 1.0

To be able to use HasRows, you'll need the .NET Framework version 1.1 (this forum is supposed to discuss 1.1 issues only, but the differences between the versions are not always clear).

You can download version 1.1 from the Microsoft site at: http://msdn.microsoft.com/netframework/

Check here and here for more information about the HasRows property.

Cheers,

Imar

(Sorry for the confusion. In an earlier post I said HasRows is available in version 1.0, while I meant 1.1.)

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 8th, 2003, 05:49 AM
Authorized User
 
Join Date: Jun 2003
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

Thanks Imar,

I didn't relise my version was out of date

Tim :)

TDA





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:37 AM
selected value of nested repeater-build <select> bttrflii ASP.NET 2.0 Professional 2 September 15th, 2006 09:52 AM
a problem in book<<beginning asp.net using vb>> luoware ASP.NET 1.0 and 1.1 Basics 3 December 8th, 2003 09:32 PM
<<ASP.NET Security>>,download files in chapter 8 alaix All Other Wrox Books 1 July 24th, 2003 10:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.