views:

41

answers:

1

Is it possible to select multiple gridview rows using Ctrl+Click and then delete all the selected rows with a button?

+3  A: 

You can have a hidden field on the page that gets updated with each row ID in some sort of delimited list. Using jQuery, you can easily add a click event to each row that will add the ID to the hidden field on the client. After clicking a bunch of rows, the hidden field might look something like "3,65,245,111"

Here is a bit of jQuery to get you started. This will assign a click event to each row of a table with the ID "myTable":

$(document).ready(function() {
  $('#myTable tr').click(function() {
     //Insert your code to handle the click event and assign the row value to your hidden textbox
  });
});

The above will make it so that you can handle each time a row is clicked. You'll need to write a bit of code and be creative to figure out how to get the ID of the clicked row.

A separate "delete all rows" button would take the value in the hidden field, split the string at each comma and then delete each row one at a time.

There are lots of different ways to skin this cat and the above is a quick and simple way to get the job done.

Alison
Any suggestion for which jQuery plugin i can use?
WeeShian
You don't need a plugin and I don't believe that one exists for exactly this purpose. This can all be done with basic jQuery. I've updated my answer to get you going.
Alison