Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

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
0
ayha1999
Asked:
ayha1999
  • 4
  • 4
1 Solution
 
GaryCommented:
Stop what loop?
0
 
ayha1999Author Commented:
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;
            }

        }
0
 
GaryCommented:
Where are you setting i to be equal to 0
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
ayha1999Author Commented:
Outside of the loop

 int i = 0;
        foreach (GridViewRow row in gvSTLFiles.Rows)
        {
0
 
GaryCommented:
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
0
 
ayha1999Author Commented:
can you give a me a solution?
0
 
GaryCommented:
foreach (GridViewRow row in gvFiles.Rows)
        {
            CheckBox chkSelect = ((CheckBox)row.FindControl("chkBxSelect"));
            if (chkSelect.Checked == true)
            {
                i = 1;
                break;
            }
        }


            if (i == 0)
            {
                lblmsg.Text = "Please select an item.";
                proceed = false;
            }
0
 
ayha1999Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now