Ticket T600397
Visible to All Users

How to do Select All in MVC GridView with a checkbox column and Update all Checked rows

created 7 years ago

Hi,
We are trying to implement Select All in MVC Gridview using a checkbox column and Update all checked rows…Appreciate your help on this…
Attaching 3 Views

index.shtml
grandresultsRFAPAGridViewPartial.shtml
grantresultsRFAPAPartial.shtml

controller

GrantResultsRFA

Model

GrantRFAPAViewModel

Class

GrantUpdate.cs

Thanks,
Rajesh

Answers approved by DevExpress Support

created 7 years ago

Hello Rajesh,
In your scenario I suggest using the ClientGridView.SelectAllRowsOnPage method to select all unselected rows displayed on a current GridView page.

As for updating all the selected rows at once in a corresponding controller action, you can use the following approach:

  1. Pass key values of all the selected rows as an action parameter using the ClientGridView.PerformCallback method:
JavaScript
function OnUpdateSelectedRows(s, e) { var keys = grid.GetSelectedKeysOnPage(); grid.PerformCallback({ selectedIDs: keys.join() }); }
  1. In a controller action, convert a passed string to a corresponding array of a key value and update all the rows at the data source level. For example:
C#
public ActionResult CustomCallbackAction(string selectedIDs) { string[] arrayIDs = selectedIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List<Person> persons = PersonsList.GetPersons(); for(int i = 0; i < arrayIDs.Length; i++) { Person editedPerson = persons.Where(m => m.PersonID == Convert.ToInt32(arrayIDs[i])).First(); if(editedPerson != null) { editedPerson.FirstName = editedPerson.FirstName + " (UPDATED)"; } } return PartialView("GridViewPartial", PersonsList.GetPersons()); }

I have attached a sample project to demonstrate this approach in action.
I hope you will find this sample helpful.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.