473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Array Question???

Can someone please tell me how I can automatically generate the textbox
numbers in this statement...

EG:
- tbMenuItem1.text, tbMenuItem2.text etc etc...
- tbMenuItem(i) doesn't work

I would actually also like to create the FOR statement so it automatically
checked how many textboxes there was in the form so it new the number of
times to loop and create the correct number of SQL parameters...

Any help appritiated...

<CODE>

For i As Integer = 0 To 11
'Gets values of menu text textbox and sends it to the database... For
menu text
cmd.Parameters.Add(New SqlParameter("@mItem" & (i),
SqlDbType.NVarChar, 255)).Value = tbMenuItem1.Text
Next
Nov 19 '05 #1
5 1021
Tim::.. wrote:
Can someone please tell me how I can automatically generate the textbox
numbers in this statement...

EG:
- tbMenuItem1.text, tbMenuItem2.text etc etc...
- tbMenuItem(i) doesn't work

I would actually also like to create the FOR statement so it automatically
checked how many textboxes there was in the form so it new the number of
times to loop and create the correct number of SQL parameters...

Any help appritiated...

<CODE>

For i As Integer = 0 To 11
'Gets values of menu text textbox and sends it to the database... For
menu text
cmd.Parameters.Add(New SqlParameter("@mItem" & (i),
SqlDbType.NVarChar, 255)).Value = tbMenuItem1.Text
Next


I would recommend storing the number of textboxes you have on the webform in
ViewState which will make things easier. I don't have VS in front of me, so
this is untested, but should work.

========= code below =========

Dim intTextBoxCount As Integer = ViewState("TextBoxCount")

For i As Integer = 0 To intTextBoxCount - 1

cmd.Parameters.Add(New SqlParameter("@mItem" & i.ToString(), _
SqlDbType.NVarChar, 255)).Value = _
CType(Page.FindControl("tbMenuItem" & i.ToString()), TextBox).Text

Next

Good luck,
Ben
Nov 19 '05 #2
Thanks...

But how does the ViewState count the testboxes???

"Ben Amada" wrote:
Tim::.. wrote:
Can someone please tell me how I can automatically generate the textbox
numbers in this statement...

EG:
- tbMenuItem1.text, tbMenuItem2.text etc etc...
- tbMenuItem(i) doesn't work

I would actually also like to create the FOR statement so it automatically
checked how many textboxes there was in the form so it new the number of
times to loop and create the correct number of SQL parameters...

Any help appritiated...

<CODE>

For i As Integer = 0 To 11
'Gets values of menu text textbox and sends it to the database... For
menu text
cmd.Parameters.Add(New SqlParameter("@mItem" & (i),
SqlDbType.NVarChar, 255)).Value = tbMenuItem1.Text
Next


I would recommend storing the number of textboxes you have on the webform in
ViewState which will make things easier. I don't have VS in front of me, so
this is untested, but should work.

========= code below =========

Dim intTextBoxCount As Integer = ViewState("TextBoxCount")

For i As Integer = 0 To intTextBoxCount - 1

cmd.Parameters.Add(New SqlParameter("@mItem" & i.ToString(), _
SqlDbType.NVarChar, 255)).Value = _
CType(Page.FindControl("tbMenuItem" & i.ToString()), TextBox).Text

Next

Good luck,
Ben

Nov 19 '05 #3
Tim::.. wrote:
Thanks...

But how does the ViewState count the testboxes???


It depends, but I'm guessing that you are creating the textboxes, so if you
create 5 of them (for example), then you can store the number 5 in ViewState
right after you've created them. i.e.:

ViewState("TextBoxCount") = 5

Probably the easiest way to do this is when you are creating and adding the
textboxes to your webform, use an integer variable to keep track of how many
textboxes you have created. Something like:

Dim intCount As Integer

For i As Integer = 0 To 4
' Your code that creates a textbox goes here
intCount += 1
Next

.... at this point, intCount contains the number of textboxes you have
created. So just assign intCount to ViewState("TextBoxCount").

Hopefully this will work for your situtation.

Ben
Nov 19 '05 #4
Thanks for the help Ben!
"Ben Amada" wrote:
Tim::.. wrote:
Thanks...

But how does the ViewState count the testboxes???


It depends, but I'm guessing that you are creating the textboxes, so if you
create 5 of them (for example), then you can store the number 5 in ViewState
right after you've created them. i.e.:

ViewState("TextBoxCount") = 5

Probably the easiest way to do this is when you are creating and adding the
textboxes to your webform, use an integer variable to keep track of how many
textboxes you have created. Something like:

Dim intCount As Integer

For i As Integer = 0 To 4
' Your code that creates a textbox goes here
intCount += 1
Next

.... at this point, intCount contains the number of textboxes you have
created. So just assign intCount to ViewState("TextBoxCount").

Hopefully this will work for your situtation.

Ben

Nov 19 '05 #5
Hi Tim
foreach(Control ctl in this.Controls)
{
if ctl.GetType().IsInstanceOfType(TextBox)
{
//do something....
}
}

"Tim::.." wrote:
Thanks for the help Ben!
"Ben Amada" wrote:
Tim::.. wrote:
Thanks...

But how does the ViewState count the testboxes???


It depends, but I'm guessing that you are creating the textboxes, so if you
create 5 of them (for example), then you can store the number 5 in ViewState
right after you've created them. i.e.:

ViewState("TextBoxCount") = 5

Probably the easiest way to do this is when you are creating and adding the
textboxes to your webform, use an integer variable to keep track of how many
textboxes you have created. Something like:

Dim intCount As Integer

For i As Integer = 0 To 4
' Your code that creates a textbox goes here
intCount += 1
Next

.... at this point, intCount contains the number of textboxes you have
created. So just assign intCount to ViewState("TextBoxCount").

Hopefully this will work for your situtation.

Ben

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: buda | last post by:
Hi, I've been wondering for a while now (and always forgot to ask :) what is the exact quote from the Standard that forbids the use of (&array) (when x >= number_of_columns) as stated in the FAQ...
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.