我用這個代碼能夠檢查gridview行選擇哪個工作的複選框。但是,除非單擊實際複選框,否則後面的代碼不會運行。有任何想法嗎?複選框OnCheckedChanged沒有觸發時,通過JQuery檢查複選框
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
}