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
}
}
}