1

動的に作成されたラジオ ボタン リストの束を含むテーブルがあり、ラジオ ボタン リストのそれぞれをループして、選択した項目のテキスト値を取得するコードを記述しようとしています。私は次のコードを持っています

   foreach ( Control ctrl in Table1.Controls)
    {
        if (ctrl is RadioButtonList)
        {
           //get the text value of the selected radio button 
        }
    }

しかし、その特定のコントロールに対して選択された項目の値を取得する方法にこだわっています。

4

1 に答える 1

5

これを試して:

foreach (Control ctrl in Table1.Controls)
{
    if (ctrl is RadioButtonList)
    {  
        RadioButtonList rbl = (RadioButtonList)ctrl;

        for (int i = 0; i < rbl.Items.Count; i++)
        {
            if (rbl.Items[i].Selected)
            {
                //get the text value of the selected radio button
                string value = rbl.Items[i].Text;
            }
        }
    }
}

RadioButtonList コントロールで選択されている項目を特定するには、Items コレクションを反復処理し、コレクション内の各項目の Selected プロパティをテストします。

ここを見てください: RadioButtonList Web サーバー コントロール

于 2010-03-21T19:48:25.050 に答える