即時試圖建立一個反饋表,我有一些模擬代碼類似於這樣ASP.Net單選按鈕列表
for (int i = 1; i < 3; i++)
{
TableRow tr = new TableRow();
Table1.Rows.Add(tr);
TableCell QuestionCell = new TableCell();
// get the text for the question and stick it in the cell
QuestionCell.Text = "<b>"+i+".</b> Question " + i;
tr.Cells.Add(QuestionCell);
TableRow tr2 = new TableRow();
Table1.Rows.Add(tr2);
// create a cell for the choice
TableCell ChoicesCell = new TableCell();
ChoicesCell.Width = 1000;
// align the choices on the left
ChoicesCell.HorizontalAlign = HorizontalAlign.Left;
tr2.Cells.Add(ChoicesCell);
RadioButtonList rbl = new RadioButtonList();
rbl.ID = "Radio1_" + i;
ChoicesCell.Controls.Add(rbl);
rbl.Items.Add("1");
rbl.Items.Add("2");
rbl.Items.Add("3");
rbl.Items.Add("4");
}
顯然這個代碼並不意味着什麼,它只是嘗試如何我可以做這個反饋表單,我現在遇到的問題是有一次按下了提交按鈕(表單上有一個提交按鈕),我如何瀏覽表格並從用戶選擇的單選按鈕中獲取文本?在page_load上創建的反饋!
感謝您的任何幫助!
編輯所以一旦按下按鈕
protected void Button1_Click(object sender, EventArgs e)
{
foreach (TableCell cell in Table1.Rows)
{
foreach (Control ctrl in cell.Controls)
{
if (ctrl is RadioButtonList)
{
if (ctrl.selected) // this doesnt works
{
string selected = ctrl.text // this doesnt work either
}
}
}
}
}
這似乎並不奏效我有這樣的代碼...我不知道我去錯了!
。你什麼意思?你是否遇到特定的錯誤? – jessegavin 2010-03-21 20:40:58