Created
January 29, 2021 08:52
-
-
Save jzwang-dev/1bfbcd661831fa4a5e4cdf21af636868 to your computer and use it in GitHub Desktop.
PagingAndCheckBox.aspx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="PagingAndCheckBox.aspx.vb" Inherits="PagingAndCheckBox" %> | |
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Grid View Paging + CheckBox</title> | |
<script> | |
function checkId(cb) { | |
var hidden = document.getElementById('checkedIds'); | |
var checked_ids = hidden.value ? hidden.value.split(/\s*,\s*/) : []; | |
var id = cb.parentElement.attributes['data-id'].value; | |
var index = checked_ids.indexOf(id); | |
if (cb.checked) { | |
if (index == -1) { | |
checked_ids.push(id); | |
} | |
} else { | |
if (index != -1) { | |
checked_ids.splice(index, 1); | |
} | |
} | |
hidden.value = checked_ids.join(); | |
} | |
</script> | |
</head> | |
<body> | |
<h5>測試GridView分頁 + CheckBox</h5> | |
<form id="form1" runat="server"> | |
<asp:HiddenField ID="checkedIds" runat="server" ClientIDMode="Static" /> | |
<asp:Button ID="btnTest" runat="server" Text="測試" /> | |
<asp:GridView ID="gvTest" runat="server" HeaderStyle-BackColor="LightGray" AlternatingRowStyle-BackColor="LightGray" CellPadding="5" | |
AutoGenerateColumns="false" AllowPaging="true" PageSize="3"> | |
<Columns> | |
<asp:TemplateField> | |
<ItemTemplate> | |
<asp:CheckBox ID="cbCheck" runat="server" data-id='<%#Eval("Id") %>' onclick="checkId(this)" /> | |
</ItemTemplate> | |
</asp:TemplateField> | |
<asp:BoundField DataField="Id" HeaderText="Id" /> | |
<asp:BoundField DataField="Name" HeaderText="Name" /> | |
<asp:BoundField DataField="Email" HeaderText="Email" /> | |
</Columns> | |
</asp:GridView> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment