p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
I forgot my password Register Now
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 21st, 2009, 01:41 AM
Friend of Wrox
Points: 577, Level: 8
Points: 577, Level: 8 Points: 577, Level: 8 Points: 577, Level: 8
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 115
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 22nd, 2009, 06:46 AM
Authorized User
Points: 227, Level: 4
Points: 227, Level: 4 Points: 227, Level: 4 Points: 227, Level: 4
Activity: 10%
Activity: 10% Activity: 10% Activity: 10%
 
Join Date: May 2006
Location: , , United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you set the text to 0 in the properties box?
Or are you generating a gridview completely in code?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old October 23rd, 2009, 01:22 AM
Friend of Wrox
Points: 577, Level: 8
Points: 577, Level: 8 Points: 577, Level: 8 Points: 577, Level: 8
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 115
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old October 23rd, 2009, 03:57 AM
Authorized User
Points: 227, Level: 4
Points: 227, Level: 4 Points: 227, Level: 4 Points: 227, Level: 4
Activity: 10%
Activity: 10% Activity: 10% Activity: 10%
 
Join Date: May 2006
Location: , , United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 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>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old October 25th, 2009, 10:42 AM
Friend of Wrox
Points: 577, Level: 8
Points: 577, Level: 8 Points: 577, Level: 8 Points: 577, Level: 8
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 115
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 !!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old October 25th, 2009, 12:35 PM
Friend of Wrox
Points: 788, Level: 10
Points: 788, Level: 10 Points: 788, Level: 10 Points: 788, Level: 10
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 199
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old October 26th, 2009, 05:01 AM
Authorized User
Points: 227, Level: 4
Points: 227, Level: 4 Points: 227, Level: 4 Points: 227, Level: 4
Activity: 10%
Activity: 10% Activity: 10% Activity: 10%
 
Join Date: May 2006
Location: , , United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 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.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old October 26th, 2009, 05:03 AM
Authorized User
Points: 227, Level: 4
Points: 227, Level: 4 Points: 227, Level: 4 Points: 227, Level: 4
Activity: 10%
Activity: 10% Activity: 10% Activity: 10%
 
Join Date: May 2006
Location: , , United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 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.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 09:47 AM
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 11:33 PM
how to add from text values into excel cells kotaiah Excel VBA 2 September 12th, 2006 11:55 AM
Text box values are different shoakat Classic ASP Databases 2 April 28th, 2005 01:29 AM
loop values and text box values move mateenmohd Classic ASP Basics 2 April 6th, 2005 12:33 AM



All times are GMT -4. The time now is 04:16 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc