当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net 获取Gridview隐藏列的值

ASP.NET
Web服务器控件:LinkButton控件
Web服务器控件:ListBox控件
Web服务器控件:ListItem控件
Web服务器控件:Literal控件
Web服务器控件:Panel控件
Web服务器控件:PlaceHolder控件
Web服务器控件:RadioButton控件
Web服务器控件:RadioButtonList控件
Web服务器控件:BulletedList控件
Web服务器控件:Style控件
Web服务器控件:Table控件
Web服务器控件:TableCell控件
Web服务器控件:TableRow控件
Web服务器控件:TextBox控件
Web服务器控件:XML控件
Validation服务器控件:CompareValidator控件
Validation服务器控件:CustomValidator控件
Validation服务器控件:RangeValidator控件
Validation服务器控件:RegularExpressionValidator控件
Validation服务器控件:RequiredFieldValidator控件

ASP.NET 中的 asp.net 获取Gridview隐藏列的值


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 211 ::
收藏到网摘: n/a

asp.net 获取Gridview隐藏列的值的实现代码。 在Gridview 的 RowCreated事件中书写如下代码:
复制代码 代码如下:

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Header)
{
//隐藏第1列
e.Row.Cells[0].Visible = false;
//可以根据需要隐藏更多的列
}
}

因为在RowCreated事件(隐藏)在绑定时候发生,所以这样就即能将数据绑定到列上,又隐藏该列,所以可以访问到隐藏列的值。
复制代码 代码如下:

protected void gvUnit_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//获取隐藏列的值
if (e.Row.Cells[1].Text == "xxx")
{
//TODO
}
}
}