DataList not keeping some of its attributes.

T

tshad

I have a DataList where I am trying to set the background color to
particular DataListItems:

Dim oDLI as DataListItem = s.parent.parent
oDLI.BackColor = System.Drawing.Color.Green

This works fine.

The problem is that on any PostBack, the color is gone (empty).

The DataGrid doesn't seem to have this problem. I can set a DataGridItem
and it will stay that way unless I rebind to it.

This is similar to another problem I had setting the visible attribute
(doesn't work) for the DataListItem.

Is there a setting or something that I can set that will tell it to keep the
attribute setting?

The only other way I can figure is to set an invisible label on the
datalistitem that is nothing more than yes/no whether the color should be
there or not and I can reset it during Page_Load.

That's just a little more work than I would have thought I would have to do.

Thanks,

Tom
 
T

tshad

I actually found a better way to solve the problem (which I believe will
solve my visibility problem).
The datalistitem is what seems to have the problem (unlike the datagriditem
which seems to work fine). What seems to solve the problem is to put an
asp:panel around it all:

****************************************************************************************
<itemtemplate>
<asp:panel id="thePanel" runat="server">
<table border="0" width="100%" CellPadding="0" CellSpacing="0"
style="margin:0">
<tr>
<td>
<asp:label id="lblQuestion" Text='<%#
DataBinder.Eval(Container.DataItem, "Question") %>' runat="server" />
</td>
<td width="40px">
<asp:LinkButton Text="Move" ID="btnMove"
OnClick="SetMoveList_Click" runat="server" />
</td>
</tr>
</table>
</asp:panel>
</itemtemplate>
*****************************************************************************************

You then can change the color of the panel which will color the whole row.
It will also solve the class problem I mentioned in the other post as well
where if you set the alternatingitemstyle to a CSSClass for the backcolor,
you can't set the color programmatically. Instead of change the color of
the datalistitem, you change the color of the panel.

Tom
 

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,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top