Brian Green
Brian Green

Reputation: 567

How do I dynamically change the background color of a specific record in a datalist?

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.

Here is the code for my datalists

<asp:DataList ID="dlBRA" runat="server">
                    <ItemTemplate>
                        <table class="style1">
                            <tr>
                                <td rowspan="2">
                                    <asp:Label ID="Label3" runat="server" Text='<%#     Eval("LocationID") %>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Eval("DPCI") %>'></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="Label5" runat="server" Text='<%# Eval("Quantity") %>'></asp:Label>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>

and here is my code behind

StoreMethods.UnloadTruck(items);
    //populate and highlight the A list
    List<BRLocation> aLocs =( from A in ctx.BRLocations
                              where A.LocationID.Contains("a")
                              select A).ToList<BRLocation>();
    foreach (BRLocation loc in aLocs)
    {
        foreach (Item item in items)
        {
            if (loc.DPCI == item.DPCI)
            {
                //highlight in the datalist
            }
        }
    }
    dlBRA.DataSource = aLocs;

    dlBRA.DataBind();

Upvotes: 1

Views: 2095

Answers (1)

Muhammad Hasan Khan
Muhammad Hasan Khan

Reputation: 35146

Subscribe to itemdatabound and change the color of the item

Formatting the DataList and Repeater Based Upon Data

Upvotes: 3

Related Questions