Solved

concatenate two strings to make a textbox variable?

Posted on 2006-06-12
7
825 Views
Last Modified: 2012-05-05
I'm drawing a blank on this one.

I have more than 100 textboxes.  They each have id's such as "textbox1, textbox2, textbox3, textbox4," etc.

I want to loop through results of a SQL query, dynamically assigning the values for each of these textboxes:

for (int j=0;j<121;j++)
{
     strTxtBoxTmp = "txtBox" + (j+1);
    (strTxtBoxTmp).Text = astrMySymbols[j].ToString();
}

This won't work.  Is there a way to do this without manually writing out all the 100+ lines of textbox values?  Seems like I could just easily do this with a FOR loop.

Thanks
0
Comment
Question by:cacklebunny
[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
7 Comments
 
LVL 10

Expert Comment

by:SystemExpert
ID: 16886099
Hi,

Send Full Function

and might be declarion of your Textbox is problem

Thanks
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 20 total points
ID: 16886166
With C# 2.0 you can use something like:

            for (int j = 0; j <= 121; ++j)
            {
                TextBox t = (TextBox)this.Controls.Find("txtBox" + (j + 1).ToString(), true)[0];
                t.Text = "Value: " + astrMySumbols[j].ToString();          
            }
0
 
LVL 2

Author Comment

by:cacklebunny
ID: 16886183
I'm not exactly sure what you need, but here's a further example:

On my ASPX page, I have something like the following:

<asp:textbox maxlength="4" width="60" height="30" runat="server" style="font-size:20px;font-weight:bold" id="txtBox1" />

<asp:textbox maxlength="4" width="60" height="30" runat="server" style="font-size:20px;font-weight:bold" id="txtBox2" />

Now just imagine the above repeated more than a hundred times.

In my script, I have what is already noted above.

Thanks.
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!

 
LVL 2

Author Comment

by:cacklebunny
ID: 16886542
Hi Carl:

That doesn't seem to work. I get the following error:

 'System.Web.UI.ControlCollection' does not contain a definition for 'Find'

0
 
LVL 11

Accepted Solution

by:
Babycorn-Starfish earned 80 total points
ID: 16887899
Hi there,

this is a bit like carl_tawn's solution but for .Net 1.1

for(int i = 1; i < 4; i++)
{
      TextBox t = (TextBox)this.FindControl("textBox" + i);
         //do something with textbox t
}

hope this helps

BCS
0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 16887908
I only used three textboxes so please change the loop values.

:)
0
 
LVL 2

Author Comment

by:cacklebunny
ID: 16888185
Bingo!  Thanks, Babycorn.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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