請仔細閱讀示例代碼。
<script type="text/javascript">
function CheckUnCheckAll(chk) {
$('#<%=GridView1.ClientID %>').find("input:checkbox").each(function() {
if (this != chk) {
this.checked = chk.checked;
}
});
}
</script>
檢查例如:
<script src="jquery-1.4.1.js" type="text/javascript"></script>
<script src="jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript" >
$(document).ready(function() {
var ab = 0 ;
$("[id$=myCheck]").click(function() {
if (ab == 0) {
$('#<%=GridView1.ClientID %> >tbody >tr >td:first-child > input:checkbox').attr('checked', true);
ab = 1;
}
else {
$('#<%=GridView1.ClientID %> >tbody >tr >td:first-child > input:checkbox').attr('checked', false);
ab =0 ;
}
})
})
</script>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="myCheck" runat="server" />
</HeaderTemplate>
<ItemTemplate><asp:CheckBox ID="urCheck" runat="server" /></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UnitName" HeaderText="Unit Name" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:DropDownList ID="AttendId" runat="server" >
<asp:ListItem style="Color:Green" Text="Present" Value="0"></asp:ListItem>
<asp:ListItem style="Color:Red" Text="Absent" Value="1"></asp:ListItem>
<asp:ListItem style="Color:Blue" Text="Leave" Value="2"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我要保留選中和未選中狀態在gridview中的不同頁面之間。 – 2010-12-14 06:12:41
我不確定,但在我看來,如果您必須保留選中的項目,應該使用ajax。 – Maxymus 2010-12-14 06:15:35