Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    GridView Adding Buttons during OnLoad

    Hi, I am trying to dynamically add buttons to a gridview during the onload event.


    Code:
    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

  • #2
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Fixed


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •