如果要在GridView 控件中隱藏不必要的列,使用visible="false"後 你就無法取得這列的值了.
解決問題的方法很簡單:
--------------------------------------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//隱藏不必要的列
if ((e.Row.RowType == DataControlRowType.DataRow) || (e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.Footer))
{
e.Row.Cells[0].Visible=false;
e.Row.Cells[3].Visible=false;
}
}
--------------------------------------------------
這種解決方法還是比較簡單的,以前也遇到這種問題,只是沒有寫出來,現在寫出來以供大家查詢用。