在gridview asp.net中移动选择记录

时间:2011-04-17 07:22:19

标签: asp.net gridview click row shift

嘿伙计们, 我有一个gridview,每页显示10条记录,现在我想在gridview中实现shift + click选项,当用户点击第一行并按Shift键并点击第5行时,所有行都在1到5之间(1应该选择5和包括...

任何人都可以建议我应该如何在javascript中执行此操作。

1 个答案:

答案 0 :(得分:0)

我收回了它,我为gridview找到了shift+click multiple select解决方案。所有的功劳都归功于asp论坛上的mdv。

var _sPreviousRow = null;
function wsCheckRange(p_oGridView, p_oControl, e) {
    var l_sCheckID = p_oControl.id;
    var l_aCheckIDParts = l_sCheckID.split(p_oGridView.id);
    var l_sCurrentRow = l_aCheckIDParts[1].split('_')[1].substring(3);

    var l_oEvent = (window.event) ? event : e;
    if (l_oEvent.shiftKey) {
        if (_sPreviousRow != null && _sPreviousRow != l_sCurrentRow) {
            var l_iFirst = 0, l_iLast = 0;
            if (parseInt(_sPreviousRow,10) > parseInt(l_sCurrentRow,10)) {
                l_iFirst = parseInt(l_sCurrentRow,10);
                l_iLast = parseInt(_sPreviousRow,10);
            }
            else {
                l_iFirst = parseInt(_sPreviousRow,10);
                l_iLast = parseInt(l_sCurrentRow,10);
            }
            for (var i = l_iFirst; i < l_iLast; i++) {
                var l_sLastRow = (i <= 9 ? '0' + i : i);
                var l_sCtrlNew = l_sCheckID.replace('ctl' + l_sCurrentRow, 'ctl' + l_sLastRow);
                var l_oCtrlNew = $get(l_sCtrlNew);
                if (l_oCtrlNew) {
                    l_oCtrlNew.checked = p_oControl.checked;
                }
            }
        }
        _sPreviousRow = null;
    }
    else {
        _sPreviousRow = l_sCurrentRow;
    }
}