Solved

Better way to interate through Checkboxes

Posted on 2014-04-17
8
203 Views
Last Modified: 2014-04-18
Please Help
  I have the following code that iterates through thousands of textboxes in mvc 4 to see which ones are checked. The problem is that it takes to long. Is there  a faster way of finding out which boxes are check without iterating through all of them
checkbox.rtf
0
Comment
Question by:vcurtis
[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
8 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 40007255
have you thought about using a FOR EACH loop ?
0
 

Author Comment

by:vcurtis
ID: 40007262
Yes I thought about a 4 each but I am using BeginForms and it complained about it.
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 40007269
ah I see
well in that case your pretty much confired to the for loop with that array :(
0
Industry Leaders: 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!

 

Author Comment

by:vcurtis
ID: 40007277
Thank you but there that would take longer seeing that I have thousands of records
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 40007909
"to see which ones are checked"

Are you sure you put the right code snippet up there?  The code provided isn't checking anything, it's just writing each checkbox onto the page... did I miss something?
0
 

Author Comment

by:vcurtis
ID: 40007945
Yes it is writing the code to the page but it takes so long for it to do it. I only have about 2500 records that contain 5 columns apiece.
 I would put the full code  but that would be asking to much of you guys. I was hoping there would be a faster way of the computer just processing the checked boxes and avoiding the rest

  This is the actual database call:


public void DeleteOrganization(IList<OrganizationVM> organizationList)
            {
                  foreach (var organization in organizationList.Where(o => o.IsSelected))
                  {
                        DeleteOrganization(organization.OrgId);
                  }
            }
0
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 500 total points
ID: 40008438
The short answer is no, there is no better way to iterate the data.
But for display purposes, breaking the data into chunks could help.

Maybe providing a delete button with each record that performs the individual deletion asynchronously then removes the row using javascript, similar to how Amazon does it when you remove an item from your cart.


You're displaying 2500 records to the user at a time, maybe consider paging the data with a search option or something to break it into more acceptable chunks?

To get a better understanding:
Is it taking too long to load the page displaying the check boxes?
Or is it taking too long to iterate and delete on post back?
Or both?

Are you using an ORM, in-line SQL, or Stored Procs in the back end?

Also, are you opening and closing a database connection for each deletion?


Hope this helps,
Dustin
0
 

Author Closing Comment

by:vcurtis
ID: 40009005
Thanks Dustin, I broke it into chunks and that made a huge difference.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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.
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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