我有以下带有复选框的数据网格:
<asp:DataGrid id="dgExpenditures" runat="server" Width="676px" PageSize="15"
<AlternatingItemStyle BackColor="AliceBlue"></AlternatingItemStyle>
<HeaderStyle Font-Bold="true" HorizontalAlign="Center" BackColor="Silver"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Mark To Edit">
<ItemTemplate>
<asp:CheckBox ID="Checkbox1" Runat="server" CssClass="Chkbx" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="RecordID" DataField="Record ID" SortExpression="Record ID"
<asp:BoundColumn HeaderText="PSN" DataField="PSN" SortExpression="PSN" />
<asp:BoundColumn HeaderText="Dist#" DataField="Dist" SortExpression="Dist" />
<asp:BoundColumn HeaderText="Line#" DataField="Line" SortExpression="LineNum" />
<asp:BoundColumn HeaderText="Gross Amt" DataField="GrossAmt" SortExpression="GrossAmt" />
<asp:BoundColumn HeaderText="Rate(%)" DataField="Rate" SortExpression="Rate" />
<asp:BoundColumn HeaderText="Net Amt" DataField="NetAmt" SortExpression="NetAmt" />
</Columns>
</asp:DataGrid>
我还在页面上有一个删除按钮,选中后将删除通过网格循环检查的记录并删除已检查的记录。这个循环在button.click事件中。
我已经在弹出确认对话框的.aspx页面中添加了一个脚本函数,但是如果没有选择任何项目,它将会出现。如果在数据网格中选择了一个或多个复选框,我只希望它出现:
<script type="text/javascript">
function beforeDelete() {
return $('.Chkbx').is(':checked') && confirm('Are you sure you want to delete this item?');
}
</script>
所以我的问题是如何编写一个java函数来遍历数据网格,看看是否有复选框被选中?
答案 0 :(得分:0)
我略微改变了我的回报
<script type="text/javascript">
function beforeDelete() {
var n = $('input:checked').length;
return n > 0 && confirm('Are you sure you want to delete this item?');
}
</script>