View Full Version : GridView Adding Buttons during OnLoad

03-31-2011, 09:40 PM
Hi, I am trying to dynamically add buttons to a gridview during the onload event.

protected override void OnLoad(EventArgs e)

CreateFilterRows(this.Controls[0] as Table);


private void CreateFilterButtons()
//Add Filter Buttons
System.Diagnostics.Debug.WriteLine("Creating Buttons");
TableCell tcFilter = this.BottomPagerRow.FindControl("tcFilter") as TableCell;

LinkButton lnkApplyFilter = new LinkButton();
lnkApplyFilter.ID = "lnkApplyFilter";
lnkApplyFilter.Text = "Apply";
lnkApplyFilter.ToolTip = "Apply selected filters";
lnkApplyFilter.Click += new EventHandler(lnkApplyFilter_Click);

LinkButton lnkRemoveFilter = new LinkButton();
lnkRemoveFilter.ID = "lnkRemoveFilter";
lnkRemoveFilter.Text = "Remove";
lnkRemoveFilter.ToolTip = "Remove all filters";

tcFilter.Controls.Add(new LiteralControl(" "));
tcFilter.Controls.Add(new LiteralControl(" "));

The problem is that the buttons are only added on the inital page load and not being added If I do any paging or sorting, even though the CreateButtons function is still being called each time(based on what I see from the writeline). The buttons would be rendered if I added this during PreRender, but I cannot attach an event handler at that stage. How can I solve this? Thanks

04-01-2011, 01:38 AM