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

tabcontainer と 1 つのタブを作成し、タブで 5 つのメンバーを持つ 10 個のラジオボタン リスト (それぞれに ID を与えます) を作成します。そして、私はradiobuttonlistに到達するためにこのコードを書きますが、idが見つからないため到達しません:

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

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

        }
        MessageBox.Show(ss);

たとえば、最初のradiobuttonlist id : 0radioButtonですが、見つかりません。どうすればよいですか。答えてくれてありがとう...

4

1 に答える 1

0

コード全体は少しわかりにくいですが、2 セント追加してみます。

ページに対してではなくFindControlRadiobuttonListコンテナーに対して実行する必要があります。

したがって、たとえば、という名前のコントロールRadioButtonList1を asp.net パネルに追加した場合は、次のようPanel1にする必要があります。

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