Solved

Checkbox checked state

Posted on 2013-06-18
8
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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 150 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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