...

View Full Version : GridView Adding Buttons during OnLoad



NeverWin
03-31-2011, 08: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);
CreateFilterButtons();

}



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(lnkApplyFilter);
tcFilter.Controls.Add(new LiteralControl(" "));
tcFilter.Controls.Add(lnkRemoveFilter);
}



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

NeverWin
04-01-2011, 12:38 AM
Fixed



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum