How to change background color of table?

Total Post:134

Points:940
 1644  View(s)
Ratings:
Rate this:

I want to change the background color of a table whose table tag is inside HeaderTemplate in Asp:Repeater. how can I do this?

  1. Post:378

    Points:2694
    Re: How to change background color of table?

    Hi Tanuj, 


    try this:

    <asp:Repeater ID="rpt" runat="server" OnItemDataBound="rpt_ItemDataBound">
        <HeaderTemplate>
            <table>
                <tr>
                    <td id="header" style="background:green;"runat="server">
                        textBox
                    </td>
                </tr>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:TextBox ID="ed" runat="server" autocomplete="off"></asp:TextBox>
                </td>
            </tr>    </ItemTemplate>    <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>

    Sample Code Behind

    protected void rpt_ItemDataBound(object sender,RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType == ListItemType.Header)
        {
            System.Web.UI.HtmlControls.HtmlTableCell cell =(System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("header");
            cell.BgColor ="Red";
        }
    }

      Modified On Apr-05-2018 05:49:33 AM

Answer