我在页面中添加了一个全选复选框,并使用JQuery为其编写逻辑:
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.2.min.js">
</script>
<script>
$(document).ready(function () {
var chkAll = $("#<%= chkSelectAll.ClientID %>");
var domCheckbox1 = chkAll[0];
if (typeof domCheckbox1 !== "undefined") { var isChecked = domCheckbox1.checked; }
if (isChecked == true) {
$("#<%= GVAccounts.ClientID %>").find("[type='checkbox']").prop('checked', true);
}
else{
$("#<%= GVAccounts.ClientID %>").find("[type='checkbox']").prop('checked', false);
}
});
</script>
select all code会检查gridview的子网格中的所有复选框(chkSelect在下面的代码中):
<asp:Label ID="lblSelectAll" runat="server" Text="Select All : "></asp:Label>
<asp:CheckBox ID="chkSelectAll" runat="server" AutoPostBack="true" />
<asp:GridView ID="GVAccounts" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333"
GridLines="Horizontal"
style="position: relative; margin-top: 10px;">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="branch" HeaderText="Branch"
SortExpression="branch" />
<asp:BoundField DataField="no" HeaderText="Account"
SortExpression="account" />
<asp:TemplateField HeaderText="Name" SortExpression="name">
<EditItemTemplate>
<asp:TextBox ID="TextName" runat="server" Text='<%# Eval("name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelName" runat="server" Text='<%# Eval("name") + " " + Eval("surname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="type" HeaderText="Type" SortExpression="type" />
<asp:BoundField DataField="sub" HeaderText="Sub" SortExpression="sub" />
<asp:BoundField DataField="TotalAmount" HeaderText="Hold"
SortExpression="TotalAmount" />
<asp:BoundField DataField="loc" HeaderText="LOC" SortExpression="loc" />
<asp:BoundField DataField="locstatus" HeaderText="LOC status"
SortExpression="locstatus" />
<asp:BoundField DataField="HoldCalc" HeaderText="Balance" SortExpression="HoldCalc" />
<asp:BoundField DataField="odtimes" HeaderText="#OD" SortExpression="odtimes" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="nfCount" HeaderText="/ #NF" SortExpression="nfCount" HeaderStyle-HorizontalAlign="Center" />
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="gridChild" style="display: inline; position: relative; left: 15px; overflow: auto">
<asp:GridView ID="gvChildGrid" runat="server" AutoGenerateColumns="false"
BorderStyle="Double" BorderColor="#5D7B9D" Width="95%" DataKeyNames="id">
<HeaderStyle BackColor="#5D7B9D" Font-Bold="true" ForeColor="White" />
<RowStyle BackColor="#E1E1E1" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="true" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true"
oncheckedchanged="chkSelect_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="effective" HeaderText="Effective" >
<ItemStyle Width="75px" />
</asp:BoundField>
<asp:BoundField DataField="desc_" HeaderText="Desc" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="code" HeaderText="TC"
HeaderStyle-HorizontalAlign="Left" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="amount" HeaderText="Amount"
HeaderStyle-HorizontalAlign="Left" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="tracer" HeaderText="Cheq #"
HeaderStyle-HorizontalAlign="Left" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="empl" HeaderText="Empl"
HeaderStyle-HorizontalAlign="Left" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="balance" HeaderText="OD/EXT Amt">
<ItemStyle Width="125px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Note">
<ItemTemplate>
<asp:DropDownList ID="DropDownNote" runat="server"
OnSelectedIndexChanged="DropDownNote_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem></asp:ListItem>
<asp:ListItem>MWC</asp:ListItem>
<asp:ListItem>CBM</asp:ListItem>
<asp:ListItem>Return</asp:ListItem>
<asp:ListItem>TSF</asp:ListItem>
<asp:ListItem>OK NO S/C</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Note1">
<ItemTemplate>
<asp:DropDownList ID="ddNote2" runat="server"
OnSelectedIndexChanged="DropDownNote_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Selected="True">NSF</asp:ListItem>
<asp:ListItem>Funds Not Clear</asp:ListItem>
<asp:ListItem>Post Dated</asp:ListItem>
<asp:ListItem>Stale Dated</asp:ListItem>
<asp:ListItem>Stop Payment</asp:ListItem>
<asp:ListItem>Encoding Incorrect</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Branch">
<ItemTemplate>
<asp:DropDownList ID="ddBranch" runat="server" DataSourceID="BranchDataSource"
DataTextField="branch" DataValueField="branch" >
</asp:DropDownList>
<asp:SqlDataSource ID="BranchDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ThirdPartyDataConnectionString %>"
SelectCommand="SELECT [branch] FROM [branch]"></asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Account">
<ItemTemplate>
<asp:TextBox ID="TextNo" runat="server" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:DropDownList ID="ddType" runat="server" DataSourceID="typeSource"
DataTextField="Type" DataValueField="Type">
</asp:DropDownList>
<asp:SqlDataSource ID="typeSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ThirdPartyDataConnectionString %>"
SelectCommand="SELECT [Type] FROM [DMDType]"></asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sub">
<ItemTemplate><asp:TextBox ID="TextSub" Width="25px" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" Visible="false">
<ItemTemplate><asp:TextBox ID="ID" Width="25px" runat="server" Text ='<% Eval("id") %>'></asp:TextBox></ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle HorizontalAlign="Center" />
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
当我单击全选复选框时,它会选择gridview中的复选框,但不会触发gridview中复选框的后端逻辑。逻辑是,当选中一个复选框时,它应该启用gridview中的其他控件,代码如下:
Protected Sub chkSelect_CheckedChanged(sender As Object, e As EventArgs)
For Each row As GridViewRow In GVAccounts.Rows
cmd = New SqlCommand("select submitted, id, effective FROM DmdOD where no = @no and entered = '" & ddDate.SelectedItem.Text & "' order by effective, time_, seqno_dmddmhi_dmhi", conn)
cmd.Parameters.Add(New SqlParameter("@no", row.Cells(1).Text))
Dim strRead As StringReader = New StringReader(Session("xml").ToString)
Dim xml As XmlTextReader = New XmlTextReader(strRead)
Dim gvChild As GridView = DirectCast(row.FindControl("gvChildGrid"), GridView)
For Each childrow As GridViewRow In gvChild.Rows
If chk.Checked Then
childrow.Cells(8).Enabled = True
childrow.Cells(9).Enabled = True
childrow.Cells(10).Enabled = True
childrow.Cells(11).Enabled = True
childrow.Cells(12).Enabled = True
childrow.Cells(13).Enabled = True
LoadXMLFromSession(childrow, hidden)
Else
childrow.Cells(8).Enabled = False
childrow.Cells(9).Enabled = False
childrow.Cells(10).Enabled = False
childrow.Cells(11).Enabled = False
childrow.Cells(12).Enabled = False
childrow.Cells(13).Enabled = False
LoadXMLFromSession(childrow, hidden)
'Clear out values when not selected
ddNoteList.SelectedIndex = 0
ddlNote.SelectedItem.Selected = False
ddlNote.Items.FindByValue("").Selected = True
ddBranchBox.SelectedIndex = 0
txtAccountBox.Text = ""
ddTypeBox.SelectedIndex = 0
txtSubBox.Text = ""
LoadDefaultValues()
WriteXML()
'LoadXMLFromSession(childrow, hidden)
End If
Next
Next
'CheckForSubmit()
End Sub
为了让这个行为正常,我缺少什么?
答案 0 :(得分:0)
chkSelect_CheckedChanged
是一个asp.net函数,当你使用jquery选中复选框时,它不会被激发。
如果你想从jquery调用CodeBehind方法,那么你可以使用Ajax
和PageMethods
:
http://devarchive.net/sample_calling_page_methods_from_javascript_using_ajax_net.aspx
Using jQuery to directly call ASP.NET AJAX page methods -- 500 (Internal Server Error)