سؤال

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