日期:2014-05-20  浏览次数:20363 次

[求助]为什么GridView中的隐藏列读不出值啊?
我为我的GridView设置了一个BoundField(在第一列),绑定到数据表中的ID字段

通过如下方法,在其RowCommand事件中能够等到它的值:
void   GridView_All_RowCommand(object   sender,   GridViewCommandEventArgs   e)
{
if   (e.CommandName   ==   "ChangeStatus ")
{
Int32   index   =   Convert.ToInt32(e.CommandArgument);
string   ID   =   GridView_All.Rows[index].Cells[0].Text;
}
}

其中CommandArgument是通过如下方法得到的:
void   GridView_All_RowCreated(object   sender,   GridViewRowEventArgs   e)
{
if   (e.Row.RowType   ==   DataControlRowType.DataRow)
{
Button   bn   =   (Button)e.Row.Cells[8].Controls[0];

bn.CommandArgument   =   e.Row.RowIndex.ToString();
}
}


但是,当我把ID所在的BoundField德Visable设置为False的时候(因为这个ID值没必要给客户看),结果我通过:
GridView_All.Rows[index].Cells[0].Text返回的却是null了。
请问这是怎么一回事呢?   需要如何更改?   多谢多谢!

------解决方案--------------------
在页面加载的时候设置隐藏,就可以读值
------解决方案--------------------
if(!ispostback){....GridView_All.Rows[index].Cells[0].visible=false;....}
------解决方案--------------------
lnwuyaowei(风可以追我) ( ) 信誉:100 2006-06-15 08:13:00 得分: 0


绑定数据源后,列才能生成,这时才可以隐藏,楼主调用的时机不对.
GridView gdvMy = new GridView();
gdvmy.datasource = XXXX;
gdvimy.databind();
gdvmy.column[0].visible = false;