Hi happy people,
I have created a dynamic table.
It has textboxes and buttons. i’d like the button_click event to fire. But it’s not.
Below is my code. Please tell me what I am missing. I will really appreciate.
protected void btn_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
lbl.Text = btn.CommandArgument;
lbl.Text = “hi”;
}
protected void Button1_Click(object sender, EventArgs e)
{ int i = Convert.ToInt32(DropDownList1.SelectedIndex);
for ( i = 0; i < DropDownList1.SelectedIndex; i++)
{
TableRow tr = new TableRow();
//create column1
TableCell td1 = new TableCell();
Label _label = new Label();
_label.ID = "lbl" + i.ToString();
_label.Text = "Add Level Name" + i.ToString();
td1.Controls.Add(_label);
// Create column 2
TableCell td2 = new TableCell();
TextBox _text = new TextBox();
_text.ID = "txt_" + i.ToString();
td2.Controls.Add(_text);
//create button
TableCell td3 = new TableCell();
Button btn = new Button();
btn.ID = "popup";
btn.Text = "goddy";
btn.CommandArgument = "save me";
btn.Click += new EventHandler(this.btn_Click);
td3.Controls.Add(btn);
//add them
tr.Cells.Add(td1);
tr.Cells.Add(td2);
tr.Cells.Add(td3);
Table1.Rows.Add(tr);
}
}