简体   繁体   English

访问嵌套转发器

[英]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: 我有一个NumericTextBox和一个Button,按下按钮时,它会告诉中继器A根据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 这个问题与中继器B,这是中继器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: 它的行为类似于中继器A ,但是我只希望按下按钮会影响按钮位于其中的中继器,因此它不会清除中继器B其他重复中控件上引入的数据。我使用“ foreach转发器”,如下所示:

    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? 是否有类似“ forthis转发器”的功能? any ideas how i can approach this? 任何想法,我怎么能做到这一点?

Repeater s have an ItemCommand event that I think would be useful for you. Repeater具有一个ItemCommand事件,我认为这对您很有用。 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. ButtonClick事件发生时,如果尚未设置ButtonClick事件处理程序,则ItemCommand事件将吞噬它。

On the ItemCommand event you can use the e arguments to determine which button, and the sender to determine which Repeater it came from. ItemCommand事件上,可以使用e参数确定哪个按钮,并使用sender确定它来自哪个Repeater

I was a little confused by your question, but I think this is the answer you're driving to. 您的问题让我有些困惑,但是我认为这是您要解决的问题。 Does that help? 有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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