By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,574 Members | 1,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,574 IT Pros & Developers. It's quick & easy.

alternating item bgcolor in datalist with 2 columns

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.