Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:54:11+00:00 2026-06-14T19:54:11+00:00

just feeling that i’m wasting loops here = CPU time, and was wondering if

  • 0

just feeling that i’m wasting loops here = CPU time, and was wondering if there’s a way to optimize this code, or just minimize it.

Basically what the code does is, goes trough every controls inside the editOkkInfo control.
checking if the current control is an textbox, if yes, then it will perform some stuff, if no it will jumps to next if-statement. This next statement checks if we have counted 14 times(since i only have 14 textboxes), if not 14, then the loop continues, if counted 14, then the loop breaks.

Any help is appreciated, thanks in advance, and here is the code, cheers.

iterate = 0;
foreach (System.Web.UI.Control ctrl in this.editOkkInfo.Controls)
{
    if (ctrl is TextBox)
    {
        tb = (TextBox)this.FindControl(ctrl.ClientID.ToString());
        tb.Text = dt.DefaultView[0][iterate++].ToString();
    }
    if (iterate == 14)
       break;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:54:12+00:00Added an answer on June 14, 2026 at 7:54 pm

    There is no need to use FindControl, as you already have the control. Just cast it:

    iterate = 0;
    
    foreach (System.Web.UI.Control ctrl in this.editOkkInfo.Controls)
    {
        if (ctrl is TextBox)
        {
            tb = (TextBox)ctrl;
            tb.Text = dt.DefaultView[0][iterate++].ToString();
        }
    
        if (iterate == 14)
            break;
    }
    

    An additional readability improvement will do away with the looping over all controls and the is test:

    foreach (TextBox ctrl in this.editOkkInfo.Controls)
    {
        ctrl.Text = dt.DefaultView[0][iterate++].ToString();
    
        if (iterate == 14)
            break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just wondering if there is a way to reduce the amount of code needed
I have a feeling that this query is pretty easy to construct, I just
I have a feeling that this is a subjective question, but perhaps there's something
I have a feeling that this question is very simple, but I just can't
Just learned Python 3 in 7 days, and I have the feeling that there's
I am pretty new to DirectShow and really just feeling my way round at
Just feeling curious that what the difference is for the 'Project' and 'Faceted Project'?
I'm super new to CakePHP so I have a feeling that I'm probably just
Although I have a feeling that this isn't technically possible, it's worth asking anyways.
This question is a bit rhetorical. At some point i got a feeling that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.