如何在Datalist中检查子td

时间:2009-03-31 06:58:25

标签: c# asp.net datalist itemtemplate

我有一个Datalist。以下是ItemTemplate的结构:

<ItemTemplate>                                        
  <div id="driversGrid" runat="server" style="width:3500px;" >
    <table cellpadding="0" cellspacing="0" border="0" width="3500px"> 
      <tr>
        <td id="Td1" runat="server" style="visibility:hidden;">
          <asp:Label ID="lblID" runat="server" BackColor="White" Font-Bold="true" Text='<%# Eval("ID") %>'  /><br />
        </td>
        <td id="title" style="width:90px;text-align:center;">
          <asp:Label ID="lblTitle" runat="server" BackColor="White" Font-Bold="true" Text='<%# Eval("Name") %>'  /><br />
        </td>
        <td id="am0900" runat="server" style="width:90px;">&nbsp;</td>
        <td id="am0915" runat="server" style="width:90px;">&nbsp;</td>
        <td id="am0930" runat="server" style="width:90px;">&nbsp;</td>
        <td id="am0945" runat="server" style="width:90px;">&nbsp;</td>
        <td id="am1000" runat="server" style="width:90px;">&nbsp;</td>
        <td id="am1015" runat="server" style="width:90px;">&nbsp;</td>
        <td id="am1030" runat="server" style="width:90px;">&nbsp;</td>
        <td id="am1045" runat="server" style="width:90px;">&nbsp;</td>
        <td id="am1100" runat="server" style="width:90px;">&nbsp;</td>
      </tr>
    </table>
  </div>          
</ItemTemplate>

现在,在itemdatabound事件中,我以10:25 AM的形式从数据库中获取多个时间(数据)。

我操纵每个数据并将其转换为am1030(类似于itemTemplate中的td ID之一)。现在我想检查ItemTemplate中的每个td,并将​​lblID(即员工ID)与我变量中的ID进行比较,然后将tdID与操纵数据进行比较。如果匹配则改变td的背景颜色。

简而言之,我想检查一下lblID是否为3,然后获取ID为am1030的td并更改背景颜色。

需要在C#.net。

中完成

1 个答案:

答案 0 :(得分:0)

使用foreach循环迭代e.Item.Controls集合,如下所示 -

foreach (Control c in e.Item.Controls)
{
    //if c is HtmlCell, then check the ID and change the color.
}