This is a migrated thread and some comments may be shown as answers.

GridClientSelectColumn header chkbox

3 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dhuss
Top achievements
Rank 1
dhuss asked on 06 Dec 2010, 08:28 PM
I have a radGrid that has a gridclientselectcolumn. The problem I am having is when I check the header check box, only the records on the current grid page are selected/deselected. I need to select/deselect "All" the records for the grid, irregardless of how many pages the grid contains. How do you do this from the server side code (vb - vs2008) 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Dec 2010, 08:03 AM
Hello Dhuss,

The behaviour is expected since RadGrid fetches only the data that is required for the items of the currently displayed page, when paging is enabled.
If you need all items, then you should disable paging and need to use custom logic to select/deselect items. One suggestion would be saving the selecteditems keyvalue in ArraList and saving in a Session variable.

For accomplishing the complete functionality, you should take care of these scenarios:

  • Add an ItemCommand event handler to the grid.
  •  When a "Select" command occurs, store the key values for the selected row in a Session variable.
  •  When a "Deselect" command occurs, remove the key values from the Session variable.
  •  Attach OnCheckedChaged for headerCheckBox, by accessing it in ItemCreated event
  •  In the "OnCheckedChaged" handler:
                   if checked:
                         Iterate through the griditem (after disabling paging) and save the key values in Session  
                  if unchecked:
                         Remove all the key values from Session
  •  Add a PreRender event handler to the grid.
  •  In the pre-render event of the grid, traverse the rows of the grid and compare their key values to the values saved in the Session variable. Whenever you find a match, select the row.

Note: However if you have a lot of records to be displayed there will be performance penalties.

Refer the documentation which should shed some light on accomplishing the functionality:
http://www.telerik.com/help/aspnet-ajax/grdpersistselectedrowsonsorting.html

Thanks,
Princy.
0
dhuss
Top achievements
Rank 1
answered on 07 Dec 2010, 09:22 PM
I tried your example from http://www.telerik.com/community/forums/aspnet-ajax/grid/select-all-rows-event.aspx. Using vb.net, the line to create the eventhandler will error out. It says "Public Event CheckedChanged(sender as Object, e as System.EventArgs) is an event and cannot be called directly. Use a 'RaiseEvent' statement to raise an event". I can create a new eventhandler with "dim xxx as new eventhandler(address of yyy), but it is only valid inside the sub and you can't bind it to the header check box. I tried to use "SelectedIndexChanged", but it only fires when the header checkbox is checked, not un-checked. I tried adding a commandname to the gridclientselectcolumn and trap it in the ItemCommand and that doesn't work. So at this point in time I may have to revert back to the asp:grid (which has the oncheckedchanged built in). Hint for Telerik to add this event to the client select column!!  Also, your link produces a 404 error. I did find the correct link and this example doesn't use a client select column and it only refers to griddataitems not header items. Suggestions??
0
dhuss
Top achievements
Rank 1
answered on 09 Dec 2010, 12:27 AM
Okay, I got the CheckedChanged event created and tied to the headerChkBox.CheckedChanged as per your instructions. We use a datatable beings our entire system is database driven and store it in a session variable. The CheckedChanged event will set the datatable records to selected/deselected based on the value of the checkbox. The prerender event then handles the datagrid record selection. If I select/deselect the header checkbox ("All"), it fires the CheckedChanged event and marks all the records as selected/deselected, which I want. If I change pages every record is still checked, good so far. If I deselect a single record on any page, the header checkbox is deselected which then fires the CheckedChanged event. Because the header checkbox is now deselected, all the records are deselected and every page will have zero records selected. Another scenerio that does the same thing is when a page has a single record and you select the record. The header checkbox is then selected by default and this in turn fires the CheckedChanged event which then marks every record in the datatable as selected. Basically, any method of selecting records can cause the CheckChanged event to fire when the default behavior is applied to the header checkbox. So, you can end up with a "All" or "None" scenerio. Users will check an "All" button to save time marking a large number of records and then deselect the ones they don't want. Because of the scenerios I listed, the user has to take "All" the records or manually check each record and if they check all the records on a single page, one of the following scenerios will happen.
Tags
Grid
Asked by
dhuss
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
dhuss
Top achievements
Rank 1
Share this question
or