0

我写了这段代码:

  TabContainer TabContainer1 = new TabContainer();
        TabContainer1.ID = "TabContainer1";

        HtmlTableRow row = new HtmlTableRow();
        HtmlTableCell cell = new HtmlTableCell();



        for (int toplam_grp = 0; toplam_grp < 1; toplam_grp++)
        {



        Panel my_panel= new Panel();
        my_panel.ID = toplam_grp + "my_panel";
        for (int j = 0; j < 10; j++)
        {
            Label my_label = new Label();

            my_label.ID = j + 10 * toplam_grp + "mylabel";//burda 10 j nin sınırı olcak

            my_label.Text = "asdasdas";

            RadioButtonList radioButtonList = new RadioButtonList();
            radioButtonList.ID = j + 10 * toplam_grp + "radioButton";
            radioButtonList.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
         for (int i = 0; i < 5; i++)
            { 
                radioButtonList.Items.Add(((char)(i + 65)).ToString());                
            }
            my_panel.Controls.Add(my_label);           /////////////////////////burda yanyana gözükse daha iyi olur
            my_panel.Controls.Add(radioButtonList);

        }



        TabPanel tab = new TabPanel();
        tab.ID = toplam_grp+"tab1";
        tab.HeaderText =toplam_grp+"nbr";

        TabContainer1.Tabs.Add(tab);
        TabContainer1.Tabs[toplam_grp].Controls.Add(my_panel);

        }

        cell.Controls.Add(TabContainer1);
        row.Cells.Add(cell);

        myplace.Rows.Add(row);

我创建了一个选项卡容器和一个选项卡,并在选项卡中创建了 10 个单选按钮列表(我给它们每个 id),其中有 5 个成员。我写了这段代码来到达单选按钮列表,但我没有到达,因为没有找到他们的 ID:

string ss = "";
        for (int i = 0; i < 10; i++)
        {

            ss += ((RadioButtonList)(FindControl(i + "radioButton"))).SelectedIndex + "\n";

        }
        MessageBox.Show(ss);

例如第一个单选按钮列表 id:0radioButton 但找不到。我该怎么办。谢谢您的回答...

4

1 回答 1

0

整个代码对我来说有点混乱,但我尝试添加我的 2 美分。

您需要FindControl针对RadiobuttonList容器而不是针对页面执行。

因此,例如,如果您将一个名为的控件添加到名为RadioButtonList1asp.net 的面板Panel1中,您将不得不

 Panel1.FindControl("RadioButtonList1 ")
于 2012-02-10T14:22:52.873 回答