1、GridView的列設置 復制代碼 代碼如下:
<asp:TemplateField HeaderStyle-CssClass="check" ItemStyle-CssClass="check">
<HeaderTemplate>
<input type="checkbox" onclick="selectAll(this)" />
全選
</HeaderTemplate>
<ItemTemplate>
<input name="chkIDCardNum" type="checkbox"
value="<%# Eval("PID") %>$<%# Eval("IdentityCard")%>$<%# Eval("PName")%>"
<%# "1" == Eval("IsCouldDelete").ToString()?"disabled='disabled'":""%> />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true" HeaderText="刪除">
<ItemTemplate>
<asp:LinkButton id="lbtnDelete" CommandName="lbtnDelete" runat="server" Text="刪除檔案"
CommandArgument='<%# Eval("PID") +"$"+ Eval("IdentityCard")%>'
OnClientClick="return confirm('確認刪除?');"
Visible='<%# Eval("Termination").ToString()=="1" ? false : true %>' />
</ItemTemplate>
</asp:TemplateField>
2、全選的Js處理 復制代碼 代碼如下:
function selectAll(myself) {
var oState = myself.checked;
var checkboxes = document.getElementsByName("chkIDCardNum"); //獲取input組
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].disabled) {
} else {
checkboxes[i].checked = oState; //選擇值
}
}
}
3、後台對所選值的獲取 復制代碼 代碼如下:
var selectedIds = Request.Params["chkIDCardNum"].Split(',');
if (selectedIds.Length == 0)
return;
//int[] msgIds = Array.ConvertAll<string, int>(selectedIds, s => int.Parse(s));
int[] ids = selectedIds.Select(t => int.Parse(t.Split('$')[0])).ToArray();
string[] cards = selectedIds.Select(t => t.Split('$')[1]).ToArray();