前端检查Gridview中Checkbox列表并提示确认框

    <script language="javascript" type="text/javascript">
        function delete_confirm() {
            var count = 0;
            $(".checkbox_item:checked").each(function () {
                count++;
            });
            if (count > 0) {
                return true;
            }
            else {
                alert("没有选择任何项!");
                return false;
            }

        }
        function delete_confirm_button() {
            var count = 0;
            $(".checkbox_item:checked").each(function () {
                count++;
            });
            if (count > 0) {
                return true;
            }
            else {
                return false;
            }
        }
    </script>

 不理想,会影响到页面其它按钮的提交。

    <form id="form1" runat="server" onsubmit="return delete_confirm();">
    <div>
        <asp:Button ID="Button2" runat="server" Text="Button" OnClientClick="if(delete_confirm_button()) {return confirm('您确定删除吗?');};" OnClick="Button2_Click" />
    </div>
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableModelValidation="True">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <input id="Checkbox1" type="checkbox" class="checkbox_item" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="NewsTitle" HeaderText="标题" />
                <asp:BoundField DataField="newsDate" HeaderText="时间" />
            </Columns>
        </asp:GridView>
    </div>
    </form>
-----------------------------------------------------------------
 
this.Button1.Attributes.Add("OnClick", "return delete_confirm_button();");

 

 
posted @ 2012-08-09 23:22  寂静之秋  阅读(362)  评论(0编辑  收藏  举报
哈尔滨八零网