<
asp:GridView ID
=
"
GridView1
"
runat
=
"
server
"
AutoGenerateColumns
=
"
False
"
Height
=
"
100%
"
Width = " 1000px " OnRowDataBound = " GridView1_RowDataBound " CellPadding = " 3 " GridLines = " None "
BackColor = " White " BorderColor = " White " BorderStyle = " Ridge " BorderWidth = " 2px " CellSpacing = " 1 " DataKeyNames = " ID " >
< Columns >
< asp:TemplateField HeaderText = " 选择 " >
< ItemTemplate >
< asp:CheckBox ID = " CheckBox1 " runat = " server " />
</ ItemTemplate >
< HeaderTemplate >
< asp:CheckBox ID = " CheckBox2 " runat = " server " Text = " 全选 " onclick = " if(this.checked==true) { checkAll(); } else { clearAll(); } " />
</ HeaderTemplate >
< ItemStyle Width = " 60px " />
</ asp:TemplateField >
< asp:BoundField DataField = " ID " ReadOnly = " True " HeaderText = " ID " />
< asp:BoundField DataField = " UserName " HeaderText = " 姓名 " />
< asp:BoundField DataField = " Sex " HeaderText = " 性别 " />
< asp:BoundField DataField = " Age " HeaderText = " 年龄 " />
< asp:BoundField DataField = " Metier " HeaderText = " 职业 " />
< asp:BoundField DataField = " Degree " HeaderText = " 学历 " />
< asp:BoundField DataField = " CPUID " HeaderText = " CPUID " />
< asp:BoundField DataField = " PID " HeaderText = " 散热器ID " />
< asp:BoundField DataField = " Phone " HeaderText = " 联系电话 " />
< asp:BoundField DataField = " Email " HeaderText = " Email " />
< asp:HyperLinkField Text = " 详细 " DataNavigateUrlFields = " ID " DataNavigateUrlFormatString = " ~/manage/{0}.mspx " Target = " _blank " />
</ Columns >
< FooterStyle BackColor = " #C6C3C6 " ForeColor = " Black " />
< RowStyle BackColor = " #DEDFDE " ForeColor = " Black " />
< SelectedRowStyle BackColor = " #9471DE " Font - Bold = " True " ForeColor = " White " />
< PagerStyle BackColor = " #C6C3C6 " ForeColor = " Black " HorizontalAlign = " Right " />
< HeaderStyle BackColor = " #4A3C8C " Font - Bold = " True " ForeColor = " #E7E7FF " />
</ asp:GridView >
Width = " 1000px " OnRowDataBound = " GridView1_RowDataBound " CellPadding = " 3 " GridLines = " None "
BackColor = " White " BorderColor = " White " BorderStyle = " Ridge " BorderWidth = " 2px " CellSpacing = " 1 " DataKeyNames = " ID " >
< Columns >
< asp:TemplateField HeaderText = " 选择 " >
< ItemTemplate >
< asp:CheckBox ID = " CheckBox1 " runat = " server " />
</ ItemTemplate >
< HeaderTemplate >
< asp:CheckBox ID = " CheckBox2 " runat = " server " Text = " 全选 " onclick = " if(this.checked==true) { checkAll(); } else { clearAll(); } " />
</ HeaderTemplate >
< ItemStyle Width = " 60px " />
</ asp:TemplateField >
< asp:BoundField DataField = " ID " ReadOnly = " True " HeaderText = " ID " />
< asp:BoundField DataField = " UserName " HeaderText = " 姓名 " />
< asp:BoundField DataField = " Sex " HeaderText = " 性别 " />
< asp:BoundField DataField = " Age " HeaderText = " 年龄 " />
< asp:BoundField DataField = " Metier " HeaderText = " 职业 " />
< asp:BoundField DataField = " Degree " HeaderText = " 学历 " />
< asp:BoundField DataField = " CPUID " HeaderText = " CPUID " />
< asp:BoundField DataField = " PID " HeaderText = " 散热器ID " />
< asp:BoundField DataField = " Phone " HeaderText = " 联系电话 " />
< asp:BoundField DataField = " Email " HeaderText = " Email " />
< asp:HyperLinkField Text = " 详细 " DataNavigateUrlFields = " ID " DataNavigateUrlFormatString = " ~/manage/{0}.mspx " Target = " _blank " />
</ Columns >
< FooterStyle BackColor = " #C6C3C6 " ForeColor = " Black " />
< RowStyle BackColor = " #DEDFDE " ForeColor = " Black " />
< SelectedRowStyle BackColor = " #9471DE " Font - Bold = " True " ForeColor = " White " />
< PagerStyle BackColor = " #C6C3C6 " ForeColor = " Black " HorizontalAlign = " Right " />
< HeaderStyle BackColor = " #4A3C8C " Font - Bold = " True " ForeColor = " #E7E7FF " />
</ asp:GridView >
List<string> list = new List<string>();
foreach (GridViewRow gvr in this.GridView1.Rows)
{
if (gvr.RowType == DataControlRowType.DataRow)
{
list.Add(this.GridView1.DataKeys[gvr.RowIndex][0].ToString());
}
}
this.bo.DeleteByList(list);
foreach (GridViewRow gvr in this.GridView1.Rows)
{
if (gvr.RowType == DataControlRowType.DataRow)
{
list.Add(this.GridView1.DataKeys[gvr.RowIndex][0].ToString());
}
}
this.bo.DeleteByList(list);
GridView的DataKeyNames属性可设置几个字段的值,这样就可以获取隐藏列的值。