protected void DataList1_ItemDataBound1(object sender, DataListItemEventArgs e)
{
rbl= (RadioButtonList)e.Item.FindControl("RadioButtonList1");
cbl= (CheckBoxList)e.Item.FindControl("CheckBoxList1");
lb = (Label)e.Item.FindControl("AnswertypeLabel");
tb = (TextBox)e.Item.FindControl("TextBox1");
string s = lb.Text;
if (s == "M")
{
rbl.Visible = true;
cbl.Visible = false;
}
else if (s == "C")
{
cbl.Visible = true;
rbl.Visible = false;
}
else
{
cbl.Visible = false;
rbl.Visible = false;
tb.Visible = true;
}
}
If you're not selecting M, then control would go to C, and there you have not selected C as well. Therefore it always excutes the third -- else block. Try with
if...else if...else
.
-KR