|
|
 |
| 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.
|
 |

October 21st, 2009, 01:41 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

October 22nd, 2009, 06:46 AM
|
|
Authorized User
|
|
Join Date: May 2006
Location: , , United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can you set the text to 0 in the properties box?
Or are you generating a gridview completely in code?
|

October 23rd, 2009, 01:22 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

October 23rd, 2009, 03:57 AM
|
|
Authorized User
|
|
Join Date: May 2006
Location: , , United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|

October 25th, 2009, 10:42 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 !!
|

October 25th, 2009, 12:35 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 199
Thanks: 2
Thanked 15 Times in 15 Posts
|
|
Almost...
You will have to use the FindControl function....
((Textbox)Form1.FindControl("textboxGrp" + i.ToString)).Text == "0"
__________________
Jason Hall
|

October 26th, 2009, 05:01 AM
|
|
Authorized User
|
|
Join Date: May 2006
Location: , , United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
.. 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.
|

October 26th, 2009, 05:03 AM
|
|
Authorized User
|
|
Join Date: May 2006
Location: , , United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
.. 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 |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |