标签:
1.前台js
<script type="text/javascript">
function SetAll(obj) {
var chk = document.getElementById("<%=this.GridView1.ClientID%>").getElementsByTagName("input");
for (var i = 0; i < chk.length; i++) {
if (chk[i].id = "chkOne") {
if (chk[i].disabled == false) {
chk[i].checked = obj.checked;
}
}
}
}
</script>
2.gridview 单选和多选框的加法
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" onclick="SetAll(this)" Text="全选" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkOne" runat="server" />
</ItemTemplate>
</asp:TemplateField>
3.后台取出选中的行的信息
StringBuilder deptIDs = new StringBuilder();
foreach (GridViewRow gvr in GridView2.Rows)
{
CheckBox chk = gvr.FindControl("chkOne") as CheckBox;
if (chk.Checked)
{ deptIDs.Append(",").Append(GridView2.DataKeys[gvr.RowIndex]["RequestID"].ToString().Trim()); }
}
string[] sArray = deptIDs.ToString().Split(‘,‘);
注意:给gridview绑定DataKeyNames
标签:
原文地址:http://www.cnblogs.com/mjlblogs/p/4652019.html