all groups > visual studio .net general > january 2006 >
You're in the

visual studio .net general

group:

how to create a list of text boxes to collect a group of data in .


how to create a list of text boxes to collect a group of data in . c676228
1/5/2006 2:27:06 PM
visual studio .net general:
Hi all,
I have noticed that we can use datagrid or datalist to pull data from
database data easily.
Now my question is how to create an array of text boxes to collect user data,
The user control could look have three textboxes with each one collect
lastname, firstname and social security number respectively.
FirstNameTxtbox LastNametxtbox SSNtxtbox
In my .aspx file, I could create 10 or 20 these user controls with different
ids.
My application requires that users can add more this user control if they
need more data grids to enter more people's data.
Can somebody presents some code which dynamically create an array of user
controls, so the data in those user controls could be easily handled and
inserted into database later on.
It seems to me that controls dynamically added onto aspx page have problems
to maintain their state(data),can you shed a light on me.
--
RE: how to create a list of text boxes to collect a group of data in . lukezhan NO[at]SPAM online.microsoft.com
1/6/2006 7:29:47 AM
Hello Betty,

To dynamically add a contro in ASP.NET, you may use following code;

TextBox txtFirstName = new TextBox();
this.form1.Controls.Add(txtFirstName);
txtFirstName.ID = "txtFirstName";

txtFirstName.EnableViewState = true;

txtFirstName.Text = "Default";


When the user fill the data and click a button to post back, you can get
the value in the text box with;

Response.Write(Request.Form["txtFirstName"].ToString() );

Hope this help,

Luke
AddThis Social Bookmark Button