我写下这些代码:
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和一个标签,在标签中我创建了10个radiobuttonlist(我给它们每个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但它找不到。我该怎么办。谢谢回答......
答案 0 :(得分:0)
整个代码对我来说有点混乱,但我试着加上我的2美分。
您需要针对FindControl
容器执行RadiobuttonList
,针对该页面执行不。
因此,例如,如果您将名为RadioButtonList1
的控件添加到名为Panel1
的asp.net面板中,则必须执行
Panel1.FindControl("RadioButtonList1 ")