473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Highlight datalist row on itemDataBound event

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().Tri m() %>' 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().Tri m() %>' 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:object_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>
Nov 19 '05 #1
0 1412

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jenn | last post by:
Hi Anyone knows how to access to a value of a row in a datalist. Something like this in datagrid Dim str = MyDataGrid.Cell(0).tex I would like something like this Dim str =...
2
by: Shiju Poyilil | last post by:
Hi ! I have a requirement wherein i am binding a datalist which contains a label (Caption for the field) and some literal hidden fields and a dropdown list. When I am binding to the datalist.....
5
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.