468,780 Members | 2,166 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,780 developers. It's quick & easy.

alternating item bgcolor in datalist with 2 columns

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
Nov 18 '05 #1
1 4434
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

"Eirik Eldorsen" <ku*******@hotmail.com> wrote in message
news:V9********************@news.telia.no...
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by lydia sista via DotNetMonster.com | last post: by
2 posts views Thread by craigkenisston | last post: by
4 posts views Thread by rn5a | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.