简体   繁体   中英

Accessing Nested repeaters

Greeting, I'll try to make this short and clear

I have a NumericTextBox and a Button, upon pressing the Button it tells repeater A how many times should it repeat based on the value introduced on the NumericTextBox:

    protected void ButtonRepeaterA_Click(object sender, EventArgs e)
    {
        string x = RadNumericTextBoxRepeatsOnA.Text.Trim();
        int y = Convert.ToInt32(x);

        int[] RowCount = new int[y];
        RepeaterA.DataSource = RowCount;
        RepeaterA.DataBind();

        int currentYear = DateTime.Now.Year;

        for (int i = currentYear; i <= currentYear + 100; i++)
        {
            //DropDownCCYear.Items.Add(new RadComboBoxItem(i.ToString(), i.ToString()));

            foreach (RepeaterItem item in RepeaterA.Items)
            {
                RadComboBox DropDownCCYear = (RadComboBox)item.FindControl("DropDownCCYear");
                DropDownCCYear.Items.Add(new RadComboBoxItem(i.ToString(), i.ToString()));
            }
        }


    }

The issue arises with repeater B , which is inside repeater A

It behaves similarly to repeater A , but I only want the button presses to affect the repeater in which the button is inside, so it won't clear the data introduced on the controls inside the other repetitions of repeater B , which is what happens if i use a "foreach repeater" as follows:

    protected void ButtonRepeaterB(object sender, EventArgs e)
    {

        foreach (RepeaterItem item in RepeaterA.Items)
        {
            Repeater RepeaterB = (Repeater)item.FindControl("RepeaterB");
            RadNumericTextBox RadNumericTextBoxRepeatsOnB = (RadNumericTextBox)item.FindControl("RadNumericTextBoxRepeatsOnB");

            string x = RadNumericTextBoxRepeatsOnB.Text.Trim();
            int y = Convert.ToInt32(x);

            int[] RowCount = new int[y];
            RepeaterB.DataSource = RowCount;
            RepeaterB.DataBind();
        }
    }

Is there a "forthis repeater"-like function? any ideas how i can approach this?

Repeater s have an ItemCommand event that I think would be useful for you. When the Button 's Click event happens, the ItemCommand event will swallow it up if you haven't set the Button 's Click event handler.

On the ItemCommand event you can use the e arguments to determine which button, and the sender to determine which Repeater it came from.

I was a little confused by your question, but I think this is the answer you're driving to. Does that help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM