Programmatically access GridView columns and manipulate

后端 未结 2 950
我寻月下人不归
我寻月下人不归 2021-01-16 01:37

I have a GridView :



        
2条回答
  •  抹茶落季
    2021-01-16 02:04

    Yes there is.

    1) You need to subscribe the RowDataBound event.
    2) Give the LinkButton an ID.
    3) Insert in codebehind

      protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
      {
        if(e.Row.RowType == DataControlRowType.DataRow)
        { 
          LinkButton _bt = e.Row.FindControl("ID") as LinkButton;
          if(_bt != null)
          {
            // have a look at the e.row.DataItem and try to get the value of your desired visibility property
            _bt.Visible = true;
          }
        }
      }
    

    4) If this does not work with accessing the DataItem, start thinking about a LinqDataSource.

提交回复
热议问题