我有與含有一個複選框每一行一個GridView,並且該列的標題是與checkAll功能的複選框:如何獲取GridView checkAll複選框不會觸發單個複選框?
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" ToolTip="Select this order" AutoPostBack="true" OnCheckedChanged="chkSelect_OnCheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
...More BoundFields
</Columns>
的SelectAllCheckboxes()
function SelectAllCheckboxes(spanChk) {
// Added as ASPX uses SPAN for checkbox
var oItem = spanChk.children;
var theBox = (spanChk.type == "checkbox") ?
spanChk : spanChk.children.item[0];
xState = theBox.checked;
elm = theBox.form.elements;
for (i = 0; i < elm.length; i++)
if (elm[i].type == "checkbox" &&
elm[i].id != theBox.id) {
//elm[i].click();
if (elm[i].checked != xState)
elm[i].click();
//elm[i].checked=xState;
}
}
我的GridView基本上背後的JavaScript的包含來自我的網站的銷售(訂單),所以美元金額。 OnCheckedChanged事件添加(如果選中)或從頁面上顯示的totalAmount中減去(如果未選中)當前行的價格。 這一切都很好,除了當我點擊checkAll複選框時,所有行復選框的所有OnCheckedChanged事件都會觸發,並且需要很長時間來處理它。由於我在OnCheckedChanged方法中所做的所有操作都是將數量相加,是否有一種方法我不能調用各個複選框的事件,只需調用一個單獨的方法即可獲取所有GridView行並將它們總和一旦?
設置AutoPostBack設置爲false是最簡單的方法。 – Tim
您也可以在服務器上完成所有操作。我的意思是,處理標頭複選框checkedchanged事件(chkAll_OnCheckedChanged),您將檢查/取消選中所有複選框,並在一個回傳中執行彙總 –
Mt. Schneiders - 當我檢查/取消勾選CheckAll中的複選框時,是否會阻止其他單個事件觸發? – user1437891