PDA

View Full Version : RadioButton trong DataList gặp vấn đề.HOT HOT



ngocquy_ytc
08-07-2009, 13:54
Trong ItemTemplate của DataList em có tạo 4 nút RadioButton và gộp chúng lại thành 1 group. Tất cả đều ko có gì nhưng nảy sinh 1 việc. Dù cho em check RadioButton như thế nào thì nó vẫn trả về giá trị RadioButton.Checked=false.
Em đã thử nhiều cách nhưng ko đc, xin các chỉ giáo, cảm ơn. Đoạn code của em:
foreach(DataListItem dlItem in DataList1.Items)
{
RadioButton rd1 = ((RadioButton)dlItem.FindControl("RadioButton1"));
RadioButton rd2 = ((RadioButton)dlItem.FindControl("RadioButton2"));
RadioButton rd3 = ((RadioButton)dlItem.FindControl("RadioButton3"));
RadioButton rd4 = ((RadioButton)dlItem.FindControl("RadioButton4"));
if (rd1 != null && rd1.Checked)// đều trả về false
{
tb2 = ((TextBox)DataList1.Items[i].FindControl("TextBox2"));
answer = tb2.Text;
}
else if (rd2 != null && rd2.Checked)// đều trả về false
{
tb3 = ((TextBox)DataList1.Items[i].FindControl("TextBox3"));
answer = tb3.Text;
}
else if (rd3 != null && rd3.Checked)// đều trả về false
{
tb4 = ((TextBox)DataList1.Items[i].FindControl("TextBox4"));
answer = tb4.Text;
}
else if (rd4 != null && rd4.Checked)// đều trả về false
{
tb5 = ((TextBox)DataList1.Items[i].FindControl("TextBox5"));
answer = tb5.Text;
}

}