GridView和CheckBox控制选择行上下移动

<asp:UctlGridViewExtender ID="GridView1" Width="200px"  AutoGenerateScrollBar="true"  VScrollHeight="150px" CssClass="GridView" runat="server"  OnRowDataBound="GridView1_RowDataBound"
AutoGenerateColumns="False">
    <Columns>
        <asp:TemplateField HeaderText="选择">
            <ItemTemplate>
                <input id="ItemCheck" type="checkbox" />
            </ItemTemplate>
            <HeaderStyle CssClass="GridViewFixedHeader" Width="30px" />
            <ItemStyle CssClass="GridViewItem" Width="30px" />
            <FooterStyle CssClass="GridViewFixedFooter" Width="30px" />
       </asp:TemplateField>
       <asp:BoundField DataField="ItemGroupName" HeaderText="分组名称" ReadOnly="True">
            <HeaderStyle CssClass="GridViewFixedHeader" Width="170px" />
            <ItemStyle CssClass="GridViewItem" Width="170px" />
            <FooterStyle CssClass="GridViewFixedFooter" Width="170px" />
        </asp:BoundField>
    </Columns>
    <RowStyle CssClass="GridViewRow" />
    <AlternatingRowStyle CssClass="GridViewAlternatingRow" />
    <EmptyDataRowStyle CssClass="GridViewEmptyDataRow" />
    <SelectedRowStyle CssClass="GridViewSelectedRow" />
    <EditRowStyle CssClass="GridViewEditRowStyle" />
</asp:UctlGridViewExtender>


<script language="javascript" type="text/javascript"> 
        var chkList = document.getElementsByName("ItemCheck"); 
 
        function upClick(){ 
            var intRowNum = chkClick();
            if (intRowNum == -1)
            {
                return false;
            }else if(intRowNum == 0)
            {
                alert("已是顶部!");
            }else
            {
                var tb = document.getElementById('<%= GridView1.ClientID%>');
                tb.moveRow(intRowNum,intRowNum-1);
                chkList[intRowNum-1].checked = true;
            }
            return false;
        }
        
        function downClick(){ 
            var intRowNum = chkClick();
            if (intRowNum == -1)
            {
                return false;
            }else if (intRowNum == chkList.length-1)
            {
                alert("已是底部!");
            }else
            {
                var tb = document.getElementById('<%= GridView1.ClientID%>');
                tb.moveRow(intRowNum,intRowNum+1);
                chkList[intRowNum+1].checked = true;    
            }
            return false;
        }
                
        function chkClick(){ 
            var checkedList = "";
            var arrchecked = "";
            var intFlg = 0;
            var intReturn = 0;
            for(var i=0; i<chkList.length; i++){
                if(chkList[i].checked)
                {
                    intFlg++;
                    intReturn = i;
                }
            }
            if (intFlg == 0)
            {
                alert("请选择要移动的行!");
            }else if (intFlg > 1)
            {
                alert("只可以单选!");
            }else{
                        return intReturn;
            }
                return -1;
        }
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值