Solved

Checkbox checked state

Posted on 2013-06-18
8
348 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
 
LVL 7

Author Comment

by:ayha1999
ID: 39257010
Outside of the loop

 int i = 0;
        foreach (GridViewRow row in gvSTLFiles.Rows)
        {
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now