Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing the first control in a repeater

Status
Not open for further replies.

DJVisuaL

Programmer
May 31, 2000
52
US
I want to set forecolor and backcolor of the first button in a repeater control everytime the page loads.
This is what I try
Code:
    protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Button lb = (Button)e.Item.FindControl("ListButton");
            if (e.Item.ItemIndex == 0)
            {
                lb.ForeColor = System.Drawing.Color.White;
                lb.BackColor = System.Drawing.ColorTranslator.FromHtml("#5D7B9D");
            }
        }
    }
and it does nothing
how do you know if you are on the first control?
 
ok I put this in prerender event instead and it works:
Code:
    protected void Repeater1_PreRender(object sender, EventArgs e)
    {
        Button lb = (Button)Repeater1.Items[0].FindControl("ListButton");
        lb.ForeColor = System.Drawing.Color.White;
        lb.BackColor = System.Drawing.ColorTranslator.FromHtml("#5D7B9D");
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top