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;
}
There is no need to use
FindControl, as you already have the control. Just cast it:An additional readability improvement will do away with the looping over all controls and the
istest: