468,549 Members | 2,098 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Format DataList

I am using a DataList control to display records from a database table.
The records are being rendered in a HTML table which is within the
DataList....something like this:

<form runat="server">
<asp:DataList ID="dlItem" AlternatingItemStyle-BackColor="lavender"
ItemStyle-BackColor="pink" runat="server">

<HeaderTemplate>
<table width="100%">
<tr>
<th>PRODUCT</th>
<th>PRICE</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr>
<td><%# Container.DataItem("Name") %></td>
<td><%# Container.DataItem("Price") %></td>
</tr>
</ItemTemplate>

<FooterTemplate>
<tr>
<td><b>Some Text Goes Here</b></td>
</tr>
</table>
</FooterTemplate>

</asp:DataList>
</form>

Now what I find is though the DataList displays the records, the
AlternatingItemStyle-BackColor & ItemStyle-BackColor properties that I
have set within the DataList tag don't render the back color of the
rows with the colors that I have specified. In other words, the back
color of the rows aren't set to lavender & pink alternately; rather the
back color of all the rows remain white.

Is it because I am using HTML table within the DataList control? If so,
how do I format the rows in a DataList under such circumstances?

Oct 1 '06 #1
2 1895
I've come across this behaviour too when using HTML table objects in a
DataList template. It is the default back colour of the table that is
rendered rather than that of the template.

I presume the table is there to control positioning within the
template. On the occasion when I did this I ended up abandoning this
method in favour of setting the width and height of the databound
labels to effect positioning because with the table they wouldn't line
properly with the the header.

If you need to use a table and don't want the back color to dominate,
try setting the back color of the table to transparent.

Good luck

Oct 2 '06 #2
I tried setting the background color of the table to transparent like
this:

<asp:DataList ID="dlYourCart" AlternatingItemStyle-BackColor="lavender"
ItemStyle-BackColor="pink" runat="server">
<HeaderTemplate>
<table bordercolor="black" cellspacing="0" class="format" width="100%"
style="background-image: none; background-color: transparent;">

but that doesn't make any difference - the background-color of the
entire table still remains white.

Any other ideas?

Never thought that formatting a DataList would be such a pain in the
wrong place!
Phil H wrote:
I've come across this behaviour too when using HTML table objects in a
DataList template. It is the default back colour of the table that is
rendered rather than that of the template.

I presume the table is there to control positioning within the
template. On the occasion when I did this I ended up abandoning this
method in favour of setting the width and height of the databound
labels to effect positioning because with the table they wouldn't line
properly with the the header.

If you need to use a table and don't want the back color to dominate,
try setting the back color of the table to transparent.

Good luck
Oct 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by lianfe_ravago | last post: by
5 posts views Thread by IGotYourDotNet | last post: by
reply views Thread by IGotYourDotNet | last post: by
8 posts views Thread by bienwell | last post: by
6 posts views Thread by Paul | last post: by
3 posts views Thread by Mirek Endys | last post: by
reply views Thread by JP | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.