highlight 1 row in asp:repeater

G

Guest

Hi

I'm using an asp:repeater and its DataSource/DataBind system to show a
number of records from the database. I want to highlight the latest record
(which will be the highest ID).

Any thoughts on how to do this with the repeater?

Cheers


Dan
 
G

Guest

handle the OnItemDataBound event. Set a variable ID = 0 and if the "Id" of
the current item in the handler is greater than ID, set a DataGridItem = this
current item. Then set something like datagriditem.ForeColor = "Red"...

It's not the best of explanation, but I don't have much time to write you a
code snippet. If you don't understand, ask again.

Hope that helps!
Regards,
Kostadin Kostov
 
Y

Yunus Emre ALPÖZEN

I assumed that you would change the class attribute of a table row.
<asp:repeater DataSource="<%# SourceDataTable%>" >
<ItemTemplate>
<tr class='<%# (SourceDataTable.Rows.Count==(Container.ItemIndex+1)) ?
"Selected" : "" %>'>
<td> </td>
</tr>
</ItemTemplate>
</asp:repeater>

I think, something like this would help u.

Handling events is not my way. I am not sure, but i believe this is
faster... Am I Right ?
 
E

Eliyahu Goldin

In PreRender event you have access to all repeater items when they already
have been built. You can loop through the data items, find the one with the
highest id (or just go to the last item if they are already sorted by id)
and change its visual properties as you wish.

Eliyahu
 
G

Guest

Hiya

How do I do that? Im looking at OPR now, presumably I use rptBlah.Items[x].
but I cant find anything to change anything in the HTML!

Ta
 
G

Guest

Hiya

That makes snse. However I'm struggling a bit to implement it

I created a function

private void CCItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs) {} but that didn't work
(cant use DataGridItemEventArgs with a repeater!). So I changed it to
RepeaterItemEventArgs, but I'm struggling to convert my e.Item to a
DataGridItem..

System.Web.UI.WebControls.DataGridItem dgItem;
dgItem = e.Item;

Wont let me do that! Any suggestions on how to get the e.Item to dgItem, so
I can use tihngs like .Font which arent available in e.Item ?

Cheers


Dan
 
G

Guest

I have, but how do I change anything with that? It doesnt appear to have a
Font property, or a BackColor property, or anything like InnerHtml. Help! :eek:)
 
E

Eliyahu Goldin

With the Repeater you are free to make any items. Once you get a reference
to the item, only you know what to do with it. What is the meaning of
"highlight"? It depends on what is inside the item.

Eliyahu

dhnriverside said:
Hiya

How do I do that? Im looking at OPR now, presumably I use rptBlah.Items[x].
but I cant find anything to change anything in the HTML!

Ta

Eliyahu Goldin said:
In PreRender event you have access to all repeater items when they already
have been built. You can loop through the data items, find the one with the
highest id (or just go to the last item if they are already sorted by id)
and change its visual properties as you wish.

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top