Solved

concatenate two strings to make a textbox variable?

Posted on 2006-06-12
7
821 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

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!

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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