开发者

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();


Subscribe to itemdatabound and change the color of the item

Formatting the DataList and Repeater Based Upon Data

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜