如何访问单选按钮列表

本文关键字:单选按钮 列表 访问 何访问 | 更新日期: 2023-09-27 18:23:57

我写了这个代码:

  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 : 0单选按钮,但找不到。我能做什么。感谢您的回答...

如何访问单选按钮列表

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

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

因此,例如,如果将名为 RadioButtonList1 的控件添加到名为 Panel1 的 asp.net 面板中,则必须执行

 Panel1.FindControl("RadioButtonList1 ")