GridView控件多行选择使用移动和鼠标左键 [英] gridview multiple row select using shift and left mouse button
问题描述
我需要转移与鼠标button.My要求关键支撑位,选择通过选择第一行多行,然后点击轮班preSS电网的最后一排,它选择第一排和最后一排之间的所有行。
如何实现这在ASP.NET的GridView
您应该在客户端执行此操作。在那里,你必须使用JavaScript或JQuery的使用CSS一起。而且,你应该知道, GridView控件
最终转换为HTML表中的客户端。这里有一个技巧让你尝试。请按照下列步骤。
假设的 - 在你的GridView的每一行都有一个行号和hiddenfield,表明无论是选择或不(你可以很容易地做到这一点,当你加载数据)。
-
创建一个名为两个CSS类
SelectedRow
和DefaultRow
(你可以用你喜欢这些任何名称类)。 -
在装载表首次所有行应具备的CSS类
DefaultRow
和隐藏字段的值设置为0(或任何价值,你$ P未选择$ PFER指示行)。 -
编写JavaScript或jQuery来处理第一行(TR)点击(你会在这个阶段没有preSS Shift键),并更改CSS类行(TR)到
SelectedRow
和隐藏字段值设为1。而且,保存在一个单独的隐藏字段这第一行编号很容易识别所选择的第一行。
请注意:在这个同样的功能,你应该设定的行CSS类的其余部分 DefaultRow
。这仅仅是清除所有选择,如果用户只是点击没有Shift键。
SelectedRow
。在这个阶段,你应该设置选定行的所有隐藏字段值1。下面是一个例子来处理的 Shift +单击事件JQuery的
$(文件)。点击(函数(五){
如果(e.shiftKey){
警报(SHIFT +单击)
}
});
- 现在,你可以从你的身后code阅读你的隐藏字段值,做你喜欢的任何处理所选行。
希望你了解这里的逻辑。 :)
I need shift Key support with Mouse button.My requirement is to select multiple rows by select first row and then click on last row of grid with shift press ,it select all rows between first row and last row.
How to implement this in ASP.NET Gridview
You should do this in client side. There you must use JavaScript or JQuery along with CSS. And, you should know that a GridView
is ultimately converted to a HTML table in client side. Here's a tip for you to try out. Follow these steps.
Assumption - Each row in your GridView has a row number and a hiddenfield to indicate whether it's selected or not (You can easily do this when you load data).
Create two CSS classes named
SelectedRow
andDefaultRow
(You may use any name you like for these classes).When you load the table for the first time all rows should have the CSS class
DefaultRow
and hidden field value set to 0 (or any value you prefer to indicate the rows are not selected).Write JavaScript or JQuery to handle first row (TR) click (You won't press Shift at this stage) and change the CSS class of that row (TR) to
SelectedRow
and the hidden field value to 1. And, save this first row number in a separate hidden field to easily identify the first row selected.
NOTE: In this same function you should set rest of the rows CSS class to DefaultRow
. This is just to clear all selections if the user just clicks without Shift key.
- Now. write JavaScript or JQuery to handle Shift + Click on HTML row and change the CSS class of that row (TR) and all other rows (+ or - based on the first row number) from first row selected (Row number you just saved in your hidden field) to
SelectedRow
. At this stage you should set all hidden field values of selected rows to 1.
Here's an example to handle Shift + Click event in JQuery
$(document).click(function(e) {
if (e.shiftKey) {
alert("shift+click")
}
});
- Now you can read your hidden field values from your code behind and do any processing you like on the selected rows.
Hope you understand the logic here. :)
这篇关于GridView控件多行选择使用移动和鼠标左键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!