[英]How do I change the name of a label if a specific radio button is checked?
[英]How to change label and radio button index
foreach (DataRow row in ds.Rows)
{
Label1.Text = row["ques"].ToString();
RadioButton1.Text = row["op1"].ToString();
RadioButton2.Text = row["op2"].ToString();
RadioButton3.Text = row["op3"].ToString();
RadioButton4.Text = row["op4"].ToString();
}
在这段代码中,每次循环运行时,我都希望label1.text
的值更改为label2.text
,然后再更改label2.text
label3.text
。
与单选按钮类似。
这可能吗?
如果您以前没有将控件组合到数组或列表中,则最好的方法是使用FindControl
:
int i = 1;
foreach (DataRow row in ds.Rows)
{
Label label = (Label)ParentControlId.FindControl(string.Format("Label{0}", i));
label.Text = row["ques"].ToString();
// same for radio buttons
i++;
}
请注意,应在标签或单选按钮的直接父级上调用FindControl
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.