Solved

Better way to interate through Checkboxes

Posted on 2014-04-17
8
199 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 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