?
Solved

concatenate two strings to make a textbox variable?

Posted on 2006-06-12
7
Medium Priority
?
830 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
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 80 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
Independent Software Vendors: 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 320 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 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