Gridview Cells 取值

正常顯示時用:
    GridView1.Rows[0].Cells[0].Text

如果要設定某列隱藏,同時取其值時,不能用
<asp:BoundField DataField="DepartmentId" Visible="false" />
要如此設置才可以用上面的方法取值。
protected void gvUsers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].Visible = false;
        }
    }

posted @ 2008-02-20 11:09  马建康  阅读(428)  评论(0)    收藏  举报