获取GridView 中隐藏列中的值

< 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 >
 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);

 

GridView的DataKeyNames属性可设置几个字段的值,这样就可以获取隐藏列的值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值