문제

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();
}

In this code, for each time the loop runs, i want the value of label1.text gets changes to label2.text, then label3.text and soo on.

similarly with radiobutton.

Is this possible and how.

올바른 솔루션이 없습니다

다른 팁

If you haven't assembled your controls in array or list previously, the best you can do is with 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++;
}

Note that FindControl should be called on the direct parent of the label or radio button.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top