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

DataList not keeping some of its attributes.

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


P: n/a
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
"tshad" <ts**********@ftsolutions.com> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.