views:

1916

answers:

1

Hi,

I am working on a .NET 3.5 web application and i am using GridView.

I want to select multiple rows when the user presses control key and clicks on the row.

If the clicks without pressing control key i want to do only single row selection.

How to check whether user has pressed Control key in javascript and highlight all the selected rows?

Thanks

Ashok

A: 

I hope this can provide you some help defintely.
You can capture the onkeypress and onkeyup event of each row in GridView something like this:

var isCtrl = false;

$('.GridViewRow').keyup(function (e) {<br/>
if(e.which == 17) isCtrl=false;<br/>
}).keydown(function (e) {<br/>
if(e.which == 17) isCtrl=true;<br/>
}<br/>
});<br/>

It will match all the rows whose class is "GridViewRow". So you need to specify this class to your GridView rows.
Next, toggle the background color of clicked row on its onclick event.

$('.GridViewRow').onclick(function (e) {
      // your row on click code goes here
});


Here, I have used theJQuery and you also need to include a script reference of Jquery like this:

<script language="JavaScript" src="JQuery.js"></script>
Sachin Gaur