Programmatically access GridView columns and manipulate

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

I have a GridView :



        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-16 02:24

    You can do this by adding a handler to the RowDataBound event. Add an event handler along this lines of this in your code behind:

    protected void myGrid_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
        var data = e.Row.DataItem as DataRowView;
        if (data != null)
        {
            var lbtDownload = e.Row.FindControl("lbtDownload");
            lbtDownload.Visible = (bool) data.Row["HasFileForDownload"];
        }
    }
    

    In your markup, attach the event handler to the grid:

    
    

    You will also need to assign an id to the LinkButton, matching the one that you are search for using the FindControl() method in the event handler.

    Disclaimer: I am on currently a Linux machine with no chance of testing this. Please report any bugs in the code - feel free to correct them if you have editor rights.

提交回复
热议问题