问题描述
- 求大神解答,为什么datalist中处理radiobutton的checked时string无法赋值?
- 代码如下,在最后if (strarm == tmp)判定时编译器老是提醒我tmp的值为空,不能比较,这是为什么呢?
string tmp;
RadioButton A = (RadioButton)DataList1.Items[i].FindControl(""RA"");
RadioButton B = (RadioButton)DataList1.Items[i].FindControl(""RB"");
RadioButton C = (RadioButton)DataList1.Items[i].FindControl(""RC"");
RadioButton D = (RadioButton)DataList1.Items[i].FindControl(""RD"");
Label showre = ((Label)DataList1.Items[i].FindControl(""Label4""));
string strarm = ((Label)DataList1.Items[i].FindControl(""Label3"")).Text.Trim();
if (A.Checked)
{
tmp = ""A"";} else if (B.Checked) { tmp = ""B""; } else if (C.Checked) { tmp = ""C""; } else if (D.Checked) { tmp = ""D""; } if (strarm == tmp)//问题所在,提示tmp是null { score = score + 1; }
解决方案
你有DEBUG过你的代码么?
时间: 2024-10-03 10:41:16