alternating item bgcolor in datalist with 2 columns

E

Eirik Eldorsen

I'm trying to set alternating bgcolor for a datalist with 2 columns. My
problem is that its the alternating cell that get the bgcolor, not the row.
Is it possible to set alternating color of rows?

Here is my code:

<asp:DataList id=dlKommuner runat="server" Width="400px"
RepeatColumns="2" CellPadding="3">
<AlternatingItemStyle Width="200px" CssClass="arow">
</AlternatingItemStyle>

<ItemStyle Width="200px">
</ItemStyle>

<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Name") %>' ID="Label2"></asp:Label>

</ItemTemplate>

</asp:DataList>


Eirik Eldorsen
 
E

Eliyahu Goldin

Erik,

You can't use alternating item styles to achieve what you want for the
following reason.

As far as datasource is concerned, datalist has only one column. With using
RepeatColumns=2 you are just arranging the same data column into 2 columns
on the screen. The notion of "AlternatingItem" refers to every second record
coming from the datasource. In your case you are putting every second record
in another column. That's what you get.

Now, what you should do is to get rid of alternating item styles and use
code-behind PreRender event. In the event handler loop through the datalist
rows and set another background color for every second couple of records.

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top