搜尋此網誌

2011-11-29

GridView 抓取隱藏欄位的值

DataControlField.Visible 屬性
使用 Visible 屬性顯示或隱藏資料繫結控制項中的 DataControlField 物件。
如果 Visible 屬性為 false,則不顯示資料值,並且不會往返於用戶端。如果您要使不可見的欄位資料來回往返,請將此欄位名稱加入資料繫結控制項的 DataKeyNames 屬性。

1.在別的Template欄位加入hidden field,設databinding
2.在RowCreated事件做隱藏Cell: 參考
protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.Header || 
  e.Row.RowType == DataControlRowType.DataRow)
 {
        e.Row.Cells[7].Visible = false;
    }
}


資料繫結控制項的資料繫結事件

沒有留言: