getting the record count within a repeater control

  • Thread starter Thread starter darrel
  • Start date Start date
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
 
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
 
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
 
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
 
The PreRender event is better since in that event the repeater is already
fully built and you can just loop through the items.

Eliyahu
 
Back
Top