Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7607299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:37:42+00:00 2026-05-31T00:37:42+00:00

This must be something that a lot of people have done. Basically, it’s a

  • 0

This must be something that a lot of people have done. Basically, it’s a custom GridView (i.e. inherited control) with the ability to update all rows at once. I’ve tried putting the “update all” button in various places (footer, pager, outside the grid), but it looks neatest (to me) when the button is in an extra row as the last row of the GridView.

NB: The pager row is not a suitable place for this button because this custom control could be used in a situation where paging is false. Similarly, the normal footer may be required for some other purpose (e.g. totals).

Here’s my code for putting the button in the correct place (with apologies for the terse variables etc.):

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        //Add an extra row to the table...
        if (_updateAllEnabled)
        {
          GridViewRow r = base.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal);
          Button btn = new Button();
          TableCell c = new TableCell();
          btn.ID = "UpdateAllButton";    // tried with and without this line
          btn.Text = "Update All";
          btn.Click += new EventHandler(UpdateAll);
          r.Cells.Add(c);
          c.Controls.Add(btn);
          Table t = this.Controls[0] as Table;
          c.ColumnSpan = this.Columns.Count;
          t.Rows.Add(r);           
      }
    }

This gives the appearance that I want, but the click event (UpdateAll) does not fire.

I assume that the stuff is being added too late in the life cycle (PreRender), but where else can I do this to ensure that the row is at the end of the GridView? I also thought that there might be trouble identifying the button, so I tried setting the ID. In any case, the ID in the generated HTML looks OK (consistent with “working” buttons in the pager row.

Is there a way for me to achieve this or am I attempting the impossible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:37:43+00:00Added an answer on May 31, 2026 at 12:37 am

    It would be easy to add an extra row into the grid. But the difficulty in your requirement is that the GridView’s RowCollection should not contain this row since that would be error-prone. It should also be the very last row even if paging is enabled. This is (afaik) not possible.

    Hence i’ve chosen to extend the pager with this functionality.

    I’ll add this as separate answer since my other is already too detailed and describes two different ways(footer,pager) to add controls to a GridView without extending it.

    This approach extends a GridView as in your own requirement and is similar to my other pager-approach. But it’s cleaner and only adds the additional row to the BottomPager. It woks also for every setting(AllowPaging=false,Pager-Position: Top,Bottom,BottomTop):

    [DefaultProperty("EnableUpdateAll")]
    [ToolboxData("<{0}:UpdateGridView runat=server></{0}:UpdateGridView>")]
    public class UpdateGridView : GridView
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("true")]
        [Localizable(true)]
        public bool EnableUpdateAll
        {
            get
            {
                Object val = ViewState["EnableUpdateAll"];
                return ((val == null) ? true : (bool)val);
            }
    
            set
            {
                ViewState["EnableUpdateAll"] = value;
            }
        }
    
        private bool OriginalAllowPaging
        {
            get
            {
                Object val = ViewState["OriginalAllowPaging"];
                return (bool)val;
            }
    
            set
            {
                ViewState["OriginalAllowPaging"] = value;
            }
        }
    
        private PagerPosition OriginalPagerPosition
        {
            get
            {
                Object val = ViewState["OriginalPagerPosition"];
                return (PagerPosition)val;
            }
    
            set
            {
                ViewState["OriginalPagerPosition"] = value;
            }
        }
    
        protected override void OnInit(System.EventArgs e)
        {
            if (ViewState["OriginalPagerPosition"] == null)
                OriginalPagerPosition = base.PagerSettings.Position;
            if(OriginalPagerPosition != PagerPosition.Bottom)
                PagerSettings.Position=PagerPosition.TopAndBottom;
            if (ViewState["OriginalAllowPaging"] == null)
                OriginalAllowPaging = base.AllowPaging;
            base.AllowPaging = true;
        }
    
        protected override void OnRowCreated(GridViewRowEventArgs e)
        {
            switch (e.Row.RowType)
            {
                case DataControlRowType.Pager:
                    //check if we are in BottomPager
                    if (this.Rows.Count != 0 && this.EnableUpdateAll)
                    {
                        Button btnUpdate = new Button();
                        btnUpdate.ID = "BtnUpdate";
                        btnUpdate.Text = "Update";
                        btnUpdate.Click += new EventHandler(UpdateAll);
                        var tblPager = (Table)e.Row.Cells[0].Controls[0];
                        var row = new TableRow();
                        var cell = new TableCell();
                        cell.ColumnSpan = tblPager.Rows[0].Cells.Count;
                        cell.Controls.Add(btnUpdate);
                        row.Cells.Add(cell);
                        tblPager.Rows.Add(row);
                    }
                    break;
            }
        }
    
        protected override void OnPreRender(EventArgs e)
        {
            bool bottomPagerVisible = 
                OriginalAllowPaging && 
                PageCount > 1 && 
                (OriginalPagerPosition == PagerPosition.Bottom || OriginalPagerPosition == PagerPosition.TopAndBottom);
            BottomPagerRow.Visible = bottomPagerVisible || EnableUpdateAll;
            var tblBottomPager = (Table)BottomPagerRow.Cells[0].Controls[0];
            tblBottomPager.Rows[0].Visible = bottomPagerVisible;
        }
    
        private void UpdateAll(Object sender, EventArgs e)
        {
            // do something...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I put off asking this as it must be something daft and, given it
Something must be wrong with this code right here: + (UIImage*)captureView:(UIView *)theView { UIGraphicsBeginImageContext(theView.frame.size);
There must be something wrong. I don't know what? see this on jsfiddle .
This code was working earlier today, then randomly stopped, something must of changed, but
This seems very basic and I must be missing something, but here goes anyways...
I must be missing something very simple, but can't find the answer to this.
I know SQL well but I must be missing something really dumb here. This
I tried the solution from this thread , but I must be missing something
I've scoured Google and this site pretty extensively, and I must be missing something.
This is a very simple issue. I must just be doing something stupid: This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.