checkboxs problem
-
this is code i wrote to check check boxes in datalist control but if i checked all checkboxes only it is returning true not for one or multiple checkboxes help me...:confused:
foreach (DataListItem dli in DataList1.Items)
{
CheckBox Chk = (CheckBox)dli.FindControl("CheckBox1");
if (Chk.Checked)
{
str13 = "cheked";
}
else
{
str13 = "you need to check";
}
}
LblErr.Visible = true;
LblErr.Text = str13; -
this is code i wrote to check check boxes in datalist control but if i checked all checkboxes only it is returning true not for one or multiple checkboxes help me...:confused:
foreach (DataListItem dli in DataList1.Items)
{
CheckBox Chk = (CheckBox)dli.FindControl("CheckBox1");
if (Chk.Checked)
{
str13 = "cheked";
}
else
{
str13 = "you need to check";
}
}
LblErr.Visible = true;
LblErr.Text = str13;If you are talking about the value of LblErr.Text, it will always be according to the checked state of your last item in DataList1. I am sure you can easily guess why is it so. If you want your str13 to have "cheked" for one or multiple checkbox checked, just add a break statement just after the statement
str13 = "cheked";
foreach (DataListItem dli in DataList1.Items)
{
CheckBox Chk = (CheckBox)dli.FindControl("CheckBox1");
if (Chk.Checked)
{
str13 = "cheked";
break;
}
else
{
str13 = "you need to check";
}
}
LblErr.Visible = true;
LblErr.Text = str13;This should solve your problem.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life. -
If you are talking about the value of LblErr.Text, it will always be according to the checked state of your last item in DataList1. I am sure you can easily guess why is it so. If you want your str13 to have "cheked" for one or multiple checkbox checked, just add a break statement just after the statement
str13 = "cheked";
foreach (DataListItem dli in DataList1.Items)
{
CheckBox Chk = (CheckBox)dli.FindControl("CheckBox1");
if (Chk.Checked)
{
str13 = "cheked";
break;
}
else
{
str13 = "you need to check";
}
}
LblErr.Visible = true;
LblErr.Text = str13;This should solve your problem.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life.