title: How do I dynamically change the background color of a specific record in a datalist?
body: <p>I have a list of Items and a database of Locations. My program dynamically generates a list of items and I have some of these items already in locations. I am displaying these locations in a datalist and I want to highlight the locations that contain the items.</p>
  
  <p>Here is the code for my datalists</p>
  
  <pre><code>&lt;asp:DataList ID="dlBRA" runat="server"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;table class="style1"&gt;
                              &lt;tr&gt;
                                  &lt;td rowspan="2"&gt;
                                      &lt;asp:Label ID="Label3" runat="server" Text='&lt;%#     Eval("LocationID") %&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;asp:Label ID="Label4" runat="server" Text='&lt;%# Eval("DPCI") %&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;
                                      &lt;asp:Label ID="Label5" runat="server" Text='&lt;%# Eval("Quantity") %&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/ItemTemplate&gt;
  </code></pre>
  
  <p>and here is my code behind</p>
  
  <pre><code>StoreMethods.UnloadTruck(items);
      //populate and highlight the A list
      List&lt;BRLocation&gt; aLocs =( from A in ctx.BRLocations
                                where A.LocationID.Contains("a")
                                select A).ToList&lt;BRLocation&gt;();
      foreach (BRLocation loc in aLocs)
      {
          foreach (Item item in items)
          {
              if (loc.DPCI == item.DPCI)
              {
                  //highlight in the datalist
              }
          }
      }
      dlBRA.DataSource = aLocs;
  
      dlBRA.DataBind();
  </code></pre>