我怎样才能到达单选按钮列表?

发布于 2025-01-04 08:26:49 字数 1944 浏览 0 评论 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 个成员。 我编写此代码是为了到达 radiobuttonlist,但我无法到达,因为找不到它们的 id:

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

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

        }
        MessageBox.Show(ss);

例如第一个 radiobuttonlist id:0radioButton 但找不到。我能做什么。感谢您的回答...

I write this codes :

  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);

I create a tabcontainer and one tab and in tab I create 10 radiobuttonlist(I give them ids each one) which have 5 members.
And I write this code to reach radiobuttonlist but ı dont reach because dont find their ids :

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

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

        }
        MessageBox.Show(ss);

for example first radiobuttonlist id : 0radioButton but it cant found.What can I do.Thanks for answering...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水波映月 2025-01-11 08:26:49

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

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

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

 Panel1.FindControl("RadioButtonList1 ")

The whole code is a little confusing for me but I try to add my 2 cents.

You need to execute FindControl against the RadiobuttonList container and not against the page.

So, for instance, if you added a control named RadioButtonList1 to a asp.net panel named Panel1 you would have to do

 Panel1.FindControl("RadioButtonList1 ")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文