Link to home
Start Free TrialLog in
Avatar of ayha1999
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
Avatar of Gary
Gary
Flag of Ireland image

Stop what loop?
Avatar of ayha1999
ayha1999

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("chkBxSelect"));
            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
Outside of the loop

 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
can you give a me a solution?
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks