Solved

Better way to interate through Checkboxes

Posted on 2014-04-17
8
197 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
 

Author Comment

by:vcurtis
ID: 40007277
Thank you but there that would take longer seeing that I have thousands of records
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

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!

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

15 Experts available now in Live!

Get 1:1 Help Now