So i'm making my own filter page for a gridview and have ran into some problems. When the user clicks on the add filter button, I create a row in an ASP table displaying the filter. The filtering works correctly and adds the row to the table. But att the last cell is a button that is created when the row is added to delete the filter. For some reason the delete button will not fire the event ive created for it. Any suggestions? Code that creates the tablerow and button.
Code:
private void BindDtToTable()
{
// Get the DataTable from Session
DataTable dt = (DataTable)Session["MyDt"];
// Loop through the rows
foreach (DataRow dr in dt.Rows)
{
// Create a table row
TableRow tr = new TableRow();
tr.ID = dr["id"].ToString();
// Create table cells
TableCell tc1 = new TableCell();
tc1.Text = dr["Column1"].ToString();
TableCell tc2 = new TableCell();
tc2.Text = dr["Column2"].ToString();
TableCell tc3 = new TableCell();
tc3.Text = dr["Column3"].ToString();
Button removebutton = new Button();
removebutton.Text = "Remove";
removebutton.ID = "btnRemove" + dr["id"].ToString();
removebutton.EnableViewState = true;
removebutton.Attributes.Add("runat", "server");
removebutton.Click += new EventHandler(this.removebutton_Click);
TableCell tc4 = new TableCell();
tc4.Controls.Add(removebutton);
// Add the columns to the table row
tr.Controls.Add(tc1);
tr.Controls.Add(tc2);
tr.Controls.Add(tc3);
tr.Controls.Add(tc4);
// Lastly add the row to the table
tblFilter.Controls.Add(tr);
}
}
Comment