HOW TO CHANGE BACKGROUND COLOR OF TABLE?

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
 1363  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. Sumit Kesarwani

    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";

        }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!