asp.net 獲取Gridview隱藏列的值
來源:懂視網
責編:小采
時間:2020-11-27 22:43:46
asp.net 獲取Gridview隱藏列的值
asp.net 獲取Gridview隱藏列的值:在Gridview 的 RowCreated事件中書寫如下代碼: 代碼如下:void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow e.Row.RowType =
導讀asp.net 獲取Gridview隱藏列的值:在Gridview 的 RowCreated事件中書寫如下代碼: 代碼如下:void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow e.Row.RowType =

在Gridview 的 RowCreated事件中書寫如下代碼:
代碼如下:
void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Header)
{
//隱藏第1列
e.Row.Cells[0].Visible = false;
//可以根據需要隱藏更多的列
}
}
因為在RowCreated事件(隱藏)在綁定時候發生,所以這樣就即能將數據綁定到列上,又隱藏該列,所以可以訪問到隱藏列的值。
代碼如下:
protected void gvUnit_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//獲取隱藏列的值
if (e.Row.Cells[1].Text == "xxx")
{
//TODO
}
}
}
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
asp.net 獲取Gridview隱藏列的值
asp.net 獲取Gridview隱藏列的值:在Gridview 的 RowCreated事件中書寫如下代碼: 代碼如下:void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow e.Row.RowType =