Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 21st, 2009, 12:41 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using for loop to add values in text box

Hi All !


I am using multiple text boxes to store values . I want to use a for loop to initialize the values of all text boxes to zero while loading.

the code I am using is as follows :

Code:
 
for(int i=0;i< rows.length;i++)
{
     textboxGrp[i]CP.Text="0";
     textboxGrp[i]RP.Text = "0";
     textboxGrp[i]TP.Text="0";
}


This is giving me an error.

How to manage this.

Kindly help.
  #2 (permalink)  
Old October 22nd, 2009, 05:46 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Can you set the text to 0 in the properties box?
Or are you generating a gridview completely in code?
  #3 (permalink)  
Old October 23rd, 2009, 12:22 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually there is no Gridview. I only want t populate a no. of textbox with "0" value.
The name of my TexBox controls are like textboxGrp1, textboxGrp2, textboxGrp3, textboxGrp4........textboxGrp10 . That is why I am trying to use a for loop to pupulate values using the Index of the For loop.
  #4 (permalink)  
Old October 23rd, 2009, 02:57 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Can you tell us what error is being displayed?

Check to make sure the you have a tet box called textboxGrp0 and also that the value of rows.length does not exceed the number of text boxes on the page less 1.

But still the easiest way is to set the values to zero in the .aspx page and not on the code behind page. For each Text box (in visual studio) right click, then click properties and set the Text value to 0.
<asp:Textbox ID="textboxGrp1" runat="server">0</asp:TextBox>
  #5 (permalink)  
Old October 25th, 2009, 09:42 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is no .aspx page here. It's a Windows Application page. I need to know how to get the index of the textboxes in a for loop. The error is that the control is not there if I am using

for(int i=0;i< rows.length;i++)
{
textboxGrp[i].Text="0";
textboxGrp[i].Text = "0";
textboxGrp[i].Text="0";
}

Is there any solution where I can use the Index of the for loop to assign the values to respective Textboxes. ??? I am trying to use for loop to avoid using hardcoded textboxes names as I have almost 20 textboxes whose names are in a numeric series.

Need urgent Help !!
  #6 (permalink)  
Old October 25th, 2009, 11:35 AM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Almost...

You will have to use the FindControl function....

((Textbox)Form1.FindControl("textboxGrp" + i.ToString)).Text == "0"
__________________
Jason Hall

Follow me on Twitter @jhall2013
  #7 (permalink)  
Old October 26th, 2009, 04:01 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

.. and don't forget that the series starts with 0

your examples " textboxGrp1, textboxGrp2, textboxGrp3, textboxGrp4" start with 1.

Try populating a text box with the output of your loop rather than processing the values of the text boxes.

You say you have almost 20 boxes, but in your first example you have three separate boxes. so you would need to have either 18 textboxes in 6 rows or 21 textboxes in 7 rows.

Code:
for(int i=0;i< rows.length;i++)
{
     textboxGrp[i]CP.Text="0";
textboxGrp[i]RP.Text = "0";
     textboxGrp[i]TP.Text="0";
}

In you second example it has changed

Code:
for(int i=0;i< rows.length;i++)
{
textboxGrp[i].Text="0";
textboxGrp[i].Text = "0";
textboxGrp[i].Text="0";
}

Can you show us your full code as I feel we are going round in circles a little.
including the text boxes.



  #8 (permalink)  
Old October 26th, 2009, 04:03 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

.. and don't forget that the series starts with 0

your examples " textboxGrp1, textboxGrp2, textboxGrp3, textboxGrp4" start with 1.

Try populating a text box with the output of your loop rather than processing the values of the text boxes.

You say you have almost 20 boxes, but in your first example you have three separate boxes. so you would need to have either 18 textboxes in 6 rows or 21 textboxes in 7 rows.

Code:
for(int i=0;i< rows.length;i++)
{
     textboxGrp[i]CP.Text="0";
textboxGrp[i]RP.Text = "0";
     textboxGrp[i]TP.Text="0";
}

In your second example it has changed

Code:
for(int i=0;i< rows.length;i++)
{
textboxGrp[i].Text="0";
textboxGrp[i].Text = "0";
textboxGrp[i].Text="0";
}

Can you show us your full code as I feel we are going round in circles a little.
including the text boxes.



 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get dynamic text box values Sheraz Khan ASP.NET 1.0 and 1.1 Basics 3 August 25th, 2009 08:47 AM
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
how to add from text values into excel cells kotaiah Excel VBA 2 September 12th, 2006 10:55 AM
Text box values are different shoakat Classic ASP Databases 2 April 28th, 2005 12:29 AM
loop values and text box values move mateenmohd Classic ASP Basics 2 April 5th, 2005 11:33 PM



All times are GMT -4. The time now is 03:58 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.