ayha1999
asked on
Checkbox checked state
Hi,
How can I stop the loop and display some message if user has not selected any check box in a grid view control?
Thanks
ayha
How can I stop the loop and display some message if user has not selected any check box in a grid view control?
Thanks
ayha
Stop what loop?
ASKER
I tried the following but not working. even if user not selected an item it is not displaying the message.
foreach (GridViewRow row in gvFiles.Rows)
{
CheckBox chkSelect = ((CheckBox)row.FindControl ("chkBxSel ect"));
if (chkSelect.Checked == false)
{
i += 1;
//break;
}
if (i == 0)
{
lblmsg.Text = "Please select an item.";
proceed = false;
}
}
foreach (GridViewRow row in gvFiles.Rows)
{
CheckBox chkSelect = ((CheckBox)row.FindControl
if (chkSelect.Checked == false)
{
i += 1;
//break;
}
if (i == 0)
{
lblmsg.Text = "Please select an item.";
proceed = false;
}
}
Where are you setting i to be equal to 0
ASKER
Outside of the loop
int i = 0;
foreach (GridViewRow row in gvSTLFiles.Rows)
{
int i = 0;
foreach (GridViewRow row in gvSTLFiles.Rows)
{
Your logic doesn't make sense, the first condition you are saying if not checked then increment i which means the second condition is never met if the checkbox is not checked
ASKER
can you give a me a solution?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks