Highlight datalist row on itemDataBound event

G

Guest

I am having a problem highlighting a row in a datalist during the
itemdatabound event. What is occurring is that a new td row is being wrapped
around the datalist item which is highlighted (very small), but the actual
row that I want to be highlighted is not. Style is being applied to the wrong
td row.
Following is my code for webform:

<asp:datalist ID="dlSmartKeys" Width="700" CellPadding="0"
CellSpacing="0" Runat="server">
<headertemplate>
<tr valign="top" align="right" bgColor="#d3d3d3">
<td class="dataheader" align="left">#</td>
<td class="dataheader" align="left" title="GCN Number">Gcn</td>
<td class="dataheader" align="left" title="Sk_Stc_Cde">Stc
Code</td>
<td class="dataheader" align="left" title="Sk_Hicl_Cde">Hicl
Code</td>
<td class="dataheader" align="left"
title="Sk_Strength_Cde">Strength Code</td>
<td class="dataheader" align="left"
title="Sk_Dosage_Form_Cde">Dosage Form Code</td>
<td class="dataheader" align="left"
title="Sk_Admin_Route_Cde">Admin Route Code</td>
</tr>
</headertemplate>
<itemtemplate>
<tr valign="center" align="right" bgcolor="#f5f5f5">
<input id="object_key" type="hidden" value='<%#
DataBinder.Eval(Container.DataItem, "object_key")%>' runat="server">
<td class="data" align="left" width="10"><%=Counter%>.</td>
<td class="data" align="left">
<asp:textbox ID="txtGCN" Text='<%# (DataBinder.Eval (
Container, "DataItem.Gcn_Nbr")).ToString().Trim() %>' Width="50"
MaxLength="5" Runat="server">
</asp:textbox></td>
<td class="data" align="left">
<asp:textbox ID="txtSTC" Text='<%# (DataBinder.Eval (
Container, "DataItem.Sk_Stc_Cde")).ToString().Trim() %>' Width="50"
MaxLength="4" Runat="server">abc</asp:textbox></td>
<td class="data" align="left">
<asp:textbox ID="txtHICL" Text='<%# (DataBinder.Eval (
Container, "DataItem.Sk_Hicl_Cde")).ToString().Trim() %>' Width="50"
MaxLength="5" Runat="server">abc</asp:textbox></td>
<td class="data" align="left">
<asp:textbox ID="txtSTR" Text='<%# (DataBinder.Eval (
Container, "DataItem.Sk_Strength_Cde")).ToString().Trim() %>' Width="50"
MaxLength="4" Runat="server">abc</asp:textbox></td>
<td class="data" align="left">
<asp:textbox ID="txtDOS" Text='<%# (DataBinder.Eval (
Container, "DataItem.Sk_Dosage_Form_Cde")).ToString().Trim() %>' Width="50"
MaxLength="3" Runat="server">abc</asp:textbox></td>
<td class="data" align="left">
<asp:textbox ID="txtRTE" Text='<%# (DataBinder.Eval (
Container, "DataItem.Sk_Admin_Route_Cde")).ToString().Trim() %>' Width="50"
MaxLength="2" Runat="server">abc</asp:textbox></td>
</tr>
</itemtemplate>
<footertemplate>
<tr valign="center" align="right" bgColor="dcdcdc" height="28">
<td colspan="20" align="center">
<asp:button ID="btnSubmit" OnClick="btnSubmit_OnClick"
Text="Submit Changes" CssClass="graygobtn" Runat="server"></asp:button></td>
</tr>
</footertemplate>
</asp:datalist>


and the codebehind:

private void dlSmartKeys_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.Item )
{
... biz logic
// highlight row if condition met
if (cond)
{
e.Item.BackColor=System.Drawing.Color.Red;
}
}
}

and when rendered, you can see the problem i am referring to....the new
outer td is receiving the style


<td style="background-color:Red;">
<tr valign="center" align="right" bgcolor="#f5f5f5">
<input name="dlSmartKeys:_ctl1:eek:bject_key"
id="dlSmartKeys__ctl1_object_key" type="hidden" value="702" />
<td class="data" align="left" width="10">1.</td>
<td class="data" align="left">
<input name="dlSmartKeys:_ctl1:txtGCN" type="text"
maxlength="5" id="dlSmartKeys__ctl1_txtGCN" style="width:50px;" /></td>
<td class="data" align="left">
<input name="dlSmartKeys:_ctl1:txtSTC" type="text"
maxlength="4" id="dlSmartKeys__ctl1_txtSTC" style="width:50px;" /></td>
<td class="data" align="left">
<input name="dlSmartKeys:_ctl1:txtHICL" type="text"
value="18694" maxlength="5" id="dlSmartKeys__ctl1_txtHICL"
style="width:50px;" /></td>
<td class="data" align="left">
<input name="dlSmartKeys:_ctl1:txtSTR" type="text" value="0240"
maxlength="4" id="dlSmartKeys__ctl1_txtSTR" style="width:50px;" /></td>
<td class="data" align="left">
<input name="dlSmartKeys:_ctl1:txtDOS" type="text"
maxlength="3" id="dlSmartKeys__ctl1_txtDOS" style="width:50px;" /></td>
<td class="data" align="left">
<input name="dlSmartKeys:_ctl1:txtRTE" type="text"
maxlength="2" id="dlSmartKeys__ctl1_txtRTE" style="width:50px;" /></td>
</tr>
</td>
 

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

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top