Oops, saw too late it was for c#
How to programmatically add controls to Windows Forms at run time by using c#
http://support.microsoft.c
Add Controls at Run Time
http://en.csharp-online.ne
Main Topics
Browse All TopicsHi all,
I am Using .NET2.0 framework using c#.I am facing a problem.
I want 2 generate a row of textboxes and combobox in the table
cells on click of Add button at Run Time. I also want code
to save the values entered in those boxes to the database
Please send me solution for this.
Sandeep
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Oops, saw too late it was for c#
How to programmatically add controls to Windows Forms at run time by using c#
http://support.microsoft.c
Add Controls at Run Time
http://en.csharp-online.ne
//You declare it like this:
private TextBox txtBox = new TextBox();
// when you want to add it, you use
this.Controls.Add(txtBox);
to add the content to a database table:
//declare the string containing the query to insert the data
String qry;
qry = "INSERT INTO mytable VALUES('" + txtbox.Text + txtbox1.Text + "')";
Executeqry();
//function to execute the query
private void Executeqry(string query)
{
string strSQL1 = ConfigurationSettings.AppS
SqlConnection cn = new SqlConnection();
cn.ConnectionString = strSQL1;
try {
cn = new SqlConnection(strSQL1);
cn.Open();
// Define the command
SqlCommand cmd = new SqlCommand(consulta, cn);
int ra;
ra = cmd.ExecuteNonQuery();
cn.Close();
Status.Text = "";
}
catch (Exception ex) {
Status.Text = "Error: " + ex.Message;
return; // TODO: might not be correct. Was : Exit Sub
}
finally {
if ((cn != null))
{
cn.Dispose();
}
}
}
Hi Sandeep,
You didn't specify whether you want this in a Windows Application or in a Web Application. I gues this is for a web application, because you have said 'Table'. Then, it can be done like this.
// Create DropDownList
DropDownList ddl = new DropDownList();
// Add items
ddl.Items.Add("Test1");
ddl.Items.Add("Test2");
ddl.Items.Add("Test3");
// Create TextBoxes
TextBox tb = new TextBox();
TextBox tb1 = new TextBox();
// Create TableCells
TableCell tc=new TableCell();
TableCell tc1=new TableCell();
TableCell tc2=new TableCell();
// Add Controls to TableCells
tc.Controls.Add(tb);
tc1.Controls.Add(tb1);
tc2.Controls.Add(ddl);
// Create TableRow
TableRow tr = new TableRow();
// Add TableCells to TableRow
tr.Cells.Add(tc);
tr.Cells.Add(tc1);
tr.Cells.Add(tc2);
// Create Table
Table Table1 = new Table();
// Add Row to Table1
Table1.Rows.Add(tr);
// Add Table1 to form
this.form1.Controls.Add(Ta
Like this we can add controls to a table. We can make this into one method which handles the button click event.
Then to retrieve values from the table, we have to traverse through the controls collection . But I think GridView will be the best solution for your problem. Reffer the Datavase tutorial available official ASP.Net site to learn how to add controls in the footer of the GridView.
URL : http://static.asp.net/asp.
Still if you want to use tables or if you are using Windows forms, please reply. I can help you.
PaulsGeo.
Business Accounts
Answer for Membership
by: DhaestPosted on 2007-07-03 at 05:42:35ID: 19410574
How to programmatically add controls to Windows Forms at run time by using Visual Basic 2005 or Visual Basic .NET om/default .aspx?scid =kb;en- us; Q308433&ID =kb;en-us; Q308433&SD =MSDN
http://support.microsoft.c