getting the record count within a repeater control

D

darrel

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
 
S

S. Justin Gengo

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
 
D

darrel

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
 
S

S. Justin Gengo

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
 
E

Eliyahu Goldin

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

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top