using string to make ID of controls in asp.net

Posted by Shoyebaziz123 under ASP.NET on 12/1/2009 | Views : 1645 | Status : [Member] | Replies : 2
Hi Friends,
i have an update panel in which i have a table in that i have apprxt 60 textbox......i have gave the textboxe name like txtQty1....txtQty60
at run time i am assingning that boxe to value , i have use this coding


dim str1 as string="txtQty"
dim str2 as string=".Text"

for i as integer=1 to 60
str1 + i + str2= i
Next

but its not working

how i can make str1 + i + str2 to txtQty1.Text ?

Thanks in advance




Responses

Posted by: Lakhangarg on: 12/1/2009 [Member] [Moderator] Silver

Up
0
Down
Hi-

This is not the way to assign values to the control.
Steps to Add Values:
(1) If you have added the control in a container control then find the control inside the container control. e.g you have added textbox in a panel named pnlControls.
you can find controls as.
(2) string strConstant="txtQty" ;
for(int 1=1; i<=60;I++)

{
TextBox NewTextBox=(TextBox)(pnlControls.FindControl('pnlControls'));
if(NewTextBox!=null)
{
NewTextBox.Text=i;
}
}


Thanks & Regards
Lakhan Pal Garg

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Virendradugar on: 12/2/2009 [Member] [MVP] Silver

Up
0
Down
Hi,

As you are working with VB.NET, "+" will not work. It works with C#. You have to use "&" to concate strings in VB.NET.

Here is what you can do.


dim str1 as string="txtQty"
dim str2 as string=".Text"
Dim strArray1 As ArrayList

for i as integer=1 to 60
strArray1.Add(str1 & i.ToString() & str2)
Next


Now youre strArray will be having 60 items with txtQty1.text to txtQty60.text

Hope this helps..

Thanks,
Virendra dugar

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response