By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

getting the record count within a repeater control

P: n/a
I have a repeater that I'd like to apply some logic to, namly highlighting
the top few items in the repeater. To do this, I need to determine the
record count.

I've tried this:

<%
dim highlightCount as integer = 1
%>

<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%
if (highlightCount < 3) AND DataBinder.Eval(Container.DataItem,
"Highlight").tostring = "1" then...
%>

But my code within the itemTemplate can't 'see' the 'highlightCount' integer
(I get a not declared error).

So...is there a way to get the record count via the databinder.eval
function? (or is my syntax incorrect up above?)

-Darrel
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Darrel,

I'd go about this a different way...

The repeater (like the datalist and datagrid) has an OnItemDataBound event
that fires whenever a "row" of the repeater is databound. From within this
event you could easily get the row number and use your if/then to add
highlighting to that row.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"darrel" <no*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I have a repeater that I'd like to apply some logic to, namly highlighting
the top few items in the repeater. To do this, I need to determine the
record count.

I've tried this:

<%
dim highlightCount as integer = 1
%>

<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%
if (highlightCount < 3) AND DataBinder.Eval(Container.DataItem,
"Highlight").tostring = "1" then...
%>

But my code within the itemTemplate can't 'see' the 'highlightCount'
integer
(I get a not declared error).

So...is there a way to get the record count via the databinder.eval
function? (or is my syntax incorrect up above?)

-Darrel

Nov 19 '05 #2

P: n/a
> The repeater (like the datalist and datagrid) has an OnItemDataBound event
that fires whenever a "row" of the repeater is databound. From within this
event you could easily get the row number and use your if/then to add
highlighting to that row.


Thanks. Good tip. In the end, I figured it out by just moving all my if/then
logic into a function in the codebehind. I haven't used repeaters in a while
(i've gotten in the habit of using stringbuilders as I typically have much
more control) but decided to give a repeater control another shot.

-Darrel
Nov 19 '05 #3

P: n/a
Darrel,

You're welcome. Funny, I do the same thing. Often I either go all out and
use a datagrid, but otherwise use the string builder...

I've had a couple of occasions where the datalist / repeater were the
correct controls for the project though.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"darrel" <no*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
The repeater (like the datalist and datagrid) has an OnItemDataBound
event
that fires whenever a "row" of the repeater is databound. From within
this
event you could easily get the row number and use your if/then to add
highlighting to that row.


Thanks. Good tip. In the end, I figured it out by just moving all my
if/then
logic into a function in the codebehind. I haven't used repeaters in a
while
(i've gotten in the habit of using stringbuilders as I typically have much
more control) but decided to give a repeater control another shot.

-Darrel

Nov 19 '05 #4

P: n/a
The PreRender event is better since in that event the repeater is already
fully built and you can just loop through the items.

Eliyahu

"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2***************@TK2MSFTNGP11.phx.gbl...
Darrel,

I'd go about this a different way...

The repeater (like the datalist and datagrid) has an OnItemDataBound event
that fires whenever a "row" of the repeater is databound. From within this
event you could easily get the row number and use your if/then to add
highlighting to that row.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"darrel" <no*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I have a repeater that I'd like to apply some logic to, namly highlighting the top few items in the repeater. To do this, I need to determine the
record count.

I've tried this:

<%
dim highlightCount as integer = 1
%>

<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%
if (highlightCount < 3) AND DataBinder.Eval(Container.DataItem,
"Highlight").tostring = "1" then...
%>

But my code within the itemTemplate can't 'see' the 'highlightCount'
integer
(I get a not declared error).

So...is there a way to get the record count via the databinder.eval
function? (or is my syntax incorrect up above?)

-Darrel


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.