Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Checkbox checked state

Posted on 2013-06-18
8
Medium Priority
?
387 Views
Last Modified: 2013-06-19
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
Comment
Question by:ayha1999
  • 4
  • 4
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39256874
Stop what loop?
0
 
LVL 7

Author Comment

by:ayha1999
ID: 39256918
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
 
LVL 58

Expert Comment

by:Gary
ID: 39257004
Where are you setting i to be equal to 0
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 7

Author Comment

by:ayha1999
ID: 39257010
Outside of the loop

 int i = 0;
        foreach (GridViewRow row in gvSTLFiles.Rows)
        {
0
 
LVL 58

Expert Comment

by:Gary
ID: 39257022
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
 
LVL 7

Author Comment

by:ayha1999
ID: 39257083
can you give a me a solution?
0
 
LVL 58

Accepted Solution

by:
Gary earned 600 total points
ID: 39257109
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
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 39258703
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question