转自:http://blog.itpub.net/8688837/viewspace-891166/
隐藏列的代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Visible = false; //隐藏ID列,可以取得该隐藏列的信息
}
}
点选择时取值的代码
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string str = this.GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
Response.Write(str);
}
本文介绍了在ASP.NET中使用GridView控件时如何通过代码隐藏特定的列,并在点击选择时获取这些隐藏列的值。具体实现包括在RowDataBound事件中设置列的Visible属性为false来达到隐藏的效果,以及在SelectedIndexChanging事件中通过行列索引来获取隐藏列的数据。
681

被折叠的 条评论
为什么被折叠?



