Format DataList

R

rn5a

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?
 
P

Phil H

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
 
R

rn5a

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!
 

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

Top