Dynamically creating array of controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got the
following error while I tried to assign value to ID property of dynamically
created textbox. (look at my code please )

Error: “ Object reference is not set to an instance of Objectâ€

totalRows – int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox.ID = “myTextboxâ€; //Getting error here

}

Thanks,
 
an id is a unique identifier, it seems you are passing the same value to all
of the controls.. try this..
For (int i=0; i < totalRows; i++)
{

txbox.ID = “myTextbox†+ i;

}



Bhavin said:
Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got the
following error while I tried to assign value to ID property of dynamically
created textbox. (look at my code please )

Error: “ Object reference is not set to an instance of Objectâ€

totalRows – int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox.ID = “myTextboxâ€; //Getting error here

}

Thanks,
 
Do you know how can I capture values from dynamically created controls?

an id is a unique identifier, it seems you are passing the same value to all
of the controls.. try this..
For (int i=0; i < totalRows; i++)
{

txbox.ID = “myTextbox†+ i;

}



Bhavin said:
Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got the
following error while I tried to assign value to ID property of dynamically
created textbox. (look at my code please )

Error: “ Object reference is not set to an instance of Objectâ€

totalRows – int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox.ID = “myTextboxâ€; //Getting error here

}

Thanks,
 
Angelos - Can you translate into vb.net? - Can you direct me to a newsgroup
that might if not?

Thanks

Dan

Angelos Karantzalis said:
When you create an array of objects, the objects inside it are NOT
initialized ! In other owrd, it's an array of null values mate ... change
your code to this:

Textbox[] txbox = new Textbox [totalRows];

for(int i=0; i < totalRows; i++){
txbox = new Textbox();
txbox.ID = "myTextbox"+i;
}

Angel
O:]




Bhavin said:
Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got the
following error while I tried to assign value to ID property of dynamically
created textbox. (look at my code please )

Error: " Object reference is not set to an instance of Object"

totalRows - int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox.ID = "myTextbox"; //Getting error here

}

Thanks,

 
Back
Top