[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

concatenate two strings to make a textbox variable?

Posted on 2006-06-12
7
Medium Priority
?
829 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 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
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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 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