Home > DeveloperSection > Forums > How to change background color of table?
Tanuj Kumar

Total Post:134

Points:940
Posted on    September-05-2014 12:19 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 1015  View(s)
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?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-05-2014 1:04 AM

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

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick