Below is the code to add textboxes and button dynamically on button click. I need to add tat textbox data to database on another button click. Have no idea on that. Any suggestions will be helpful.
private void button1_Click(object sender, EventArgs e)
{
int v;
v = c++;
panel1.VerticalScroll.Value = VerticalScroll.Minimum;
Button btn = new Button();
btn.Name = "btn" + v;
btn.Text = "Remove";
btn.Location = new Point(300, 5 + (30 * v));
btn.Click += new EventHandler(btn_Click);
TextBox txt = new TextBox();
txt.Name = "TextBox" + v;
txt.Location = new Point(30, 5 + (30 * v));
txt.Tag = btn;
TextBox txt1 = new TextBox();
txt1.Name = "TextBox2" + v;
txt1.Location = new Point(170, 5 + (30 * v));
txt1.Tag = btn;
panel1.Controls.Add(txt);
panel1.Controls.Add(txt1);
panel1.Controls.Add(btn);
}
private void btn_Click(object sender, EventArgs e)
{
for (int i = panel1.Controls.Count - 1; i >= 0; i--)
{
var item = panel1.Controls[i];
if (item.Tag == sender || item == sender)
panel1.Controls.Remove(item);
}
}