Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,
Iam created dynamic txtbox,dropdownlist and button also.Now i want save those values in database.
Posted
Comments
Mantu Singh 14-Mar-12 0:51am    
please clarify more.....?
Hari Krishna Prasad Inakoti 14-Mar-12 1:06am    
Table table = new Table();
table.ID = "tbl_dy";
DropDownList ddl = new DropDownList();

Page.Form.Controls.Add(table);
if (!IsPostBack)
{
for (int i = 1; i < 3; i++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
Label lbl = new Label();
lbl.ID = "lbl_'" + i + "'";
if (i == 1)
{
lbl.Text = "Name";
}
else { lbl.Text = "Salary"; }
cell.Controls.Add(new LiteralControl("  "));
TextBox txt = new TextBox();
txt.ID="txt_'"+i+"'";
cell.Controls.Add(new LiteralControl("<br/>"));
cell.Controls.Add(lbl);
cell.Controls.Add(txt);
row.Cells.Add(cell);
table.Rows.Add(row);
}
TableRow row1 = new TableRow();
TableCell cell1 = new TableCell();
Label lbl1 = new Label();
lbl1.ID = "lbl_gender";
lbl1.Text = "Gender";

ddl.Width = 180;
ddl.Height = 25;
ddl.ID = "ddl_gender";
ddl.Items.Add("Select");
ddl.Items.Add("Male");
ddl.Items.Add("Female");
cell1.Controls.Add(lbl1);
cell1.Controls.Add(new LiteralControl("  "));
cell1.Controls.Add(ddl);
row1.Cells.Add(cell1);
table.Rows.Add(row1);
}
}
Nilesh Patil Kolhapur 14-Mar-12 0:53am    
hari give some code
Hari Krishna Prasad Inakoti 14-Mar-12 1:06am    
Table table = new Table();
table.ID = "tbl_dy";
DropDownList ddl = new DropDownList();

Page.Form.Controls.Add(table);
if (!IsPostBack)
{
for (int i = 1; i < 3; i++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
Label lbl = new Label();
lbl.ID = "lbl_'" + i + "'";
if (i == 1)
{
lbl.Text = "Name";
}
else { lbl.Text = "Salary"; }
cell.Controls.Add(new LiteralControl("  "));
TextBox txt = new TextBox();
txt.ID="txt_'"+i+"'";
cell.Controls.Add(new LiteralControl("<br/>"));
cell.Controls.Add(lbl);
cell.Controls.Add(txt);
row.Cells.Add(cell);
table.Rows.Add(row);
}
TableRow row1 = new TableRow();
TableCell cell1 = new TableCell();
Label lbl1 = new Label();
lbl1.ID = "lbl_gender";
lbl1.Text = "Gender";

ddl.Width = 180;
ddl.Height = 25;
ddl.ID = "ddl_gender";
ddl.Items.Add("Select");
ddl.Items.Add("Male");
ddl.Items.Add("Female");
cell1.Controls.Add(lbl1);
cell1.Controls.Add(new LiteralControl("  "));
cell1.Controls.Add(ddl);
row1.Cells.Add(cell1);
table.Rows.Add(row1);
}
}
Sergey Alexandrovich Kryukov 14-Mar-12 1:28am    
Hari Krishna, please move your comments with code to the question itself, use "Improve question". This is because there you can format it using "pre" tags.
I also could make a special code sample, more compact, using only relevant detail, just to make the problem more clear.
--SA

Check the Google link[^]. If you have already tried something, share some code; else try some links first.
 
Share this answer
 
C#
foreach(Control c in this.Controls)
{
Textbox tb = c as Textbox;

string val = tb.Text;
}
 
Share this answer
 
Comments
SathyaRaju 14-Oct-13 0:45am    
how to find dynamic text position in c# windows application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900