423,850 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,850 IT Pros & Developers. It's quick & easy.

Active Count of Rows using Repeater Control (ASP.NET VB)

P: n/a
RC-
Hi everyone,
I have been searching and searching for an answer to this question using
Google and what not; I have not been able to find a "clear cut" answer.

OK, now the question:

I have a Repeater control that works great. What I am trying to do is
perform an active count of the number of rows that the repeater is
rendering. The end goal is to insert a page break after six rows of data. I
cannot figure out how to count the rows one by one using ASP.NET (ASP is
easy).

Any help will be greatly appreciated.

TIA,
RC-
Apr 26 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Perhaps e.Item.ItemIndex (+1)

Example:
--ASPX:
<asp:Repeater ID="rpt" runat="server">
<ItemTemplate>
something<br />
<asp:Literal ID="lit" runat="server" Visible="false"><div>Put your page
break div here.</div></asp:Literal>
</ItemTemplate>
</asp:Repeater>
--VB:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
''Just some bogus data for demo purposes:
Dim dt As New DataTable()
dt.Columns.Add("ID", Type.GetType("System.Int32"))
dt.Columns.Add("Text", Type.GetType("System.String"))
Dim q As Integer
For q = 1 To 100
Dim r As DataRow = dt.NewRow()
r("ID") = q
r("Text") = "Item #" & CStr(q)
dt.Rows.Add(r)
Next
rpt.DataSource = dt
rpt.DataBind()
End Sub

Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rpt.ItemDataBound
If (e.Item.ItemIndex + 1) Mod 6 = 0 Then
CType(e.Item.FindControl("lit"), Literal).Visible = True
End If
End Sub
---------------------------------------------------

Ray at work
"RC-" <r_******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi everyone,
I have been searching and searching for an answer to this question using
Google and what not; I have not been able to find a "clear cut" answer.

OK, now the question:

I have a Repeater control that works great. What I am trying to do is
perform an active count of the number of rows that the repeater is
rendering. The end goal is to insert a page break after six rows of data.
I cannot figure out how to count the rows one by one using ASP.NET (ASP is
easy).

Any help will be greatly appreciated.

TIA,
RC-
Apr 26 '07 #2

P: n/a
RC-
Ray,
Thank you for the post; I've almost got it to work, not entirely sure what
the code does though (very new to .NET).

I changed a couple of very small things on your original post; I removed the
bogus data and changed the name of the repeater to match my own.

I am still getting an error:

NullReferenceException was unhandled by user code

What the heck does that mean and what can I do? ( :-)

The code seems to run until the end then it throws the above error.
Thanks again,
RC-

"Ray Costanzo" <my first name at lane 34 dot commercialwrote in message
news:AA**********************************@microsof t.com...
Perhaps e.Item.ItemIndex (+1)

Example:
--ASPX:
<asp:Repeater ID="rpt" runat="server">
<ItemTemplate>
something<br />
<asp:Literal ID="lit" runat="server" Visible="false"><div>Put your page
break div here.</div></asp:Literal>
</ItemTemplate>
</asp:Repeater>
--VB:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
''Just some bogus data for demo purposes:
Dim dt As New DataTable()
dt.Columns.Add("ID", Type.GetType("System.Int32"))
dt.Columns.Add("Text", Type.GetType("System.String"))
Dim q As Integer
For q = 1 To 100
Dim r As DataRow = dt.NewRow()
r("ID") = q
r("Text") = "Item #" & CStr(q)
dt.Rows.Add(r)
Next
rpt.DataSource = dt
rpt.DataBind()
End Sub

Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rpt.ItemDataBound
If (e.Item.ItemIndex + 1) Mod 6 = 0 Then
CType(e.Item.FindControl("lit"), Literal).Visible = True
End If
End Sub
---------------------------------------------------

Ray at work
"RC-" <r_******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>Hi everyone,
I have been searching and searching for an answer to this question using
Google and what not; I have not been able to find a "clear cut" answer.

OK, now the question:

I have a Repeater control that works great. What I am trying to do is
perform an active count of the number of rows that the repeater is
rendering. The end goal is to insert a page break after six rows of data.
I cannot figure out how to count the rows one by one using ASP.NET (ASP
is easy).

Any help will be greatly appreciated.

TIA,
RC-

Apr 26 '07 #3

P: n/a
RC-
OK, I figured out why I was getting the NullReferenceException message; I
have a HeaderTemplate, SeperatorTemplate, and FooterTemplate element. I made
the code only fire on the Item element. But now the other code is not
triggering.

Here's the code I've modified:

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) _
Handles Repeater1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item) Then

If (e.Item.ItemIndex + 1) Mod 6 = 0 Then

CType(e.Item.FindControl("lit"), Literal).Visible = True

End If

End If

End Sub
Any idea why my code is not working now?
"RC-" <r_******@hotmail.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
Ray,
Thank you for the post; I've almost got it to work, not entirely sure what
the code does though (very new to .NET).

I changed a couple of very small things on your original post; I removed
the bogus data and changed the name of the repeater to match my own.

I am still getting an error:

NullReferenceException was unhandled by user code

What the heck does that mean and what can I do? ( :-)

The code seems to run until the end then it throws the above error.
Thanks again,
RC-

"Ray Costanzo" <my first name at lane 34 dot commercialwrote in message
news:AA**********************************@microsof t.com...
>Perhaps e.Item.ItemIndex (+1)

Example:
--ASPX:
<asp:Repeater ID="rpt" runat="server">
<ItemTemplate>
something<br />
<asp:Literal ID="lit" runat="server" Visible="false"><div>Put your
page break div here.</div></asp:Literal>
</ItemTemplate>
</asp:Repeater>
--VB:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
''Just some bogus data for demo purposes:
Dim dt As New DataTable()
dt.Columns.Add("ID", Type.GetType("System.Int32"))
dt.Columns.Add("Text", Type.GetType("System.String"))
Dim q As Integer
For q = 1 To 100
Dim r As DataRow = dt.NewRow()
r("ID") = q
r("Text") = "Item #" & CStr(q)
dt.Rows.Add(r)
Next
rpt.DataSource = dt
rpt.DataBind()
End Sub

Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs ) Handles
rpt.ItemDataBound
If (e.Item.ItemIndex + 1) Mod 6 = 0 Then
CType(e.Item.FindControl("lit"), Literal).Visible = True
End If
End Sub
---------------------------------------------------

Ray at work
"RC-" <r_******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>Hi everyone,
I have been searching and searching for an answer to this question using
Google and what not; I have not been able to find a "clear cut" answer.

OK, now the question:

I have a Repeater control that works great. What I am trying to do is
perform an active count of the number of rows that the repeater is
rendering. The end goal is to insert a page break after six rows of
data. I cannot figure out how to count the rows one by one using ASP.NET
(ASP is easy).

Any help will be greatly appreciated.

TIA,
RC-


Apr 26 '07 #4

P: n/a
Hi RC-,

I can't explain this, but in testing, I got the same results as you. I
discovered that if I change the IF condition, it works as expected. I'm not
sure why this is, however. Try this modified version:
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) _
Handles Repeater1.ItemDataBound
If e.Item.ItemType <ListItemType.Header And e.Item.ItemType <>
ListItemType.Footer And e.Item.ItemType <ListItemType.Separator Then
If (e.Item.ItemIndex + 1) Mod 6 = 0 Then
CType(e.Item.FindControl("lit"), Literal).Visible = True
End If
End If
End Sub
I wrote out the itemindex for e as I looped through it with the other code,
and it didn't have an index on any odd number items. Then, in another
repeateron the page, the index only existed 6 items.

Ray at work

"RC-" <r_******@hotmail.comwrote in message
news:u%****************@TK2MSFTNGP03.phx.gbl...
OK, I figured out why I was getting the NullReferenceException message; I
have a HeaderTemplate, SeperatorTemplate, and FooterTemplate element. I
made the code only fire on the Item element. But now the other code is not
triggering.

Here's the code I've modified:

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) _
Handles Repeater1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item) Then

If (e.Item.ItemIndex + 1) Mod 6 = 0 Then

CType(e.Item.FindControl("lit"), Literal).Visible = True

End If

End If

End Sub
Any idea why my code is not working now?
Apr 27 '07 #5

P: n/a
RC-
Ray,

The new code works perfectly!

Thank you so much for all your help!

RC-

"Ray Costanzo" <my first name at lane 34 dot commercialwrote in message
news:C5**********************************@microsof t.com...
Hi RC-,

I can't explain this, but in testing, I got the same results as you. I
discovered that if I change the IF condition, it works as expected. I'm
not sure why this is, however. Try this modified version:
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) _
Handles Repeater1.ItemDataBound
If e.Item.ItemType <ListItemType.Header And e.Item.ItemType <>
ListItemType.Footer And e.Item.ItemType <ListItemType.Separator Then
If (e.Item.ItemIndex + 1) Mod 6 = 0 Then
CType(e.Item.FindControl("lit"), Literal).Visible = True
End If
End If
End Sub
I wrote out the itemindex for e as I looped through it with the other
code, and it didn't have an index on any odd number items. Then, in
another repeateron the page, the index only existed 6 items.

Ray at work

"RC-" <r_******@hotmail.comwrote in message
news:u%****************@TK2MSFTNGP03.phx.gbl...
>OK, I figured out why I was getting the NullReferenceException message; I
have a HeaderTemplate, SeperatorTemplate, and FooterTemplate element. I
made the code only fire on the Item element. But now the other code is
not triggering.

Here's the code I've modified:

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs ) _
Handles Repeater1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item) Then

If (e.Item.ItemIndex + 1) Mod 6 = 0 Then

CType(e.Item.FindControl("lit"), Literal).Visible = True

End If

End If

End Sub
Any idea why my code is not working now?

Apr 27 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.