我使用此代码能够检查gridview row select 上的复选框是否有效。但是,除非我单击实际的复选框,否则后面的代码不会运行。有任何想法吗?
ASPX 代码:
<asp:GridView runat="server" ID="gvReconciledGroups" AutoGenerateColumns="false" EmptyDataText="No Reconciled Items to Batch" DataKeyNames="GroupID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="cbFinalise" AutoPostBack="true" OnCheckedChanged="cbFinalise_OnCheckedChanged" ClientIDMode="Static" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="GroupID" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" DataField="GroupID" />
<asp:BoundField HeaderText="Date" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" DataField="Date" DataFormatString="{0:dd/MM/yyyy}" ItemStyle-Width="100px" />
<asp:BoundField HeaderText="Cashier" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" DataField="Cashier" ItemStyle-Width="100px" />
脚本:
<script type="text/javascript">
$(function () {
$('tr.gridview_row,tr.gridview_alternatingRow').click(function () {
var checked = $(this).find('input[id*=cbFinalise]').prop('checked');
$(this).find('input[id*=cbFinalise]').prop('checked', !checked);
});
});
</script>
代码背后:
public void cbFinalise_OnCheckedChanged(Object sender, EventArgs e)
{
//Calculations
}