Accessing child controls of a nested repeater control

Discussion in 'ASP .Net' started by [email protected], Oct 7, 2005.

  1. Hi:

    I'm laying out a hieraracical report by nesting repeater controls. I'm
    using panels to expand/collapse detail sections. To access a panel in a
    nested repeater, I use the following code. The problem is I can get a
    reference to a nested repeater, but can not use that reference to access the
    panel within.

    protected void rptrOrders_ItemCommand(object source,
    System.Web.UI.WebControls.RepeaterCommandEventArgs e) {

    Repeater rpt = (Repeater) e.Item.FindControl("rptrItems");

    Panel pnl = (Panel) rpt.FindControl("panelItems"); // Problem here,
    returns null

    if (pnl.Visible == false) {

    pnl.Visible = true;

    }
    else {

    pnl.Visible = false;

    }
    }
     
    [email protected], Oct 7, 2005
    #1
    1. Advertisements

  2. Charlie@CBFC

    Guest Guest

    The panel named "panelItems" would be within one of the items of the child
    repeater. Try something like this:

    foreach (RepeaterItem rpi in rpt.Items)
    {
    Panel pnl = (Panel) rpi.FindControl ("panelItems");
    if ( pnl!= null) pnl.Visible =!pnl.Visible ;
    }
     
    Guest, Oct 7, 2005
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.