Using FindControl to get GridView in a Content Page

前端 未结 3 1620
忘掉有多难
忘掉有多难 2020-12-21 14:32

I would like to find a GridView Control within a separate class and I am having issues doing so. I even tried placing my code in the aspx.cs page to no avail. I

3条回答
  •  太阳男子
    2020-12-21 15:17

    Brian got it right but he forgot the essential part. You won't be able to do use his code unless you add this code on top of your HTML-Code of the file where you want to use it.(Page.aspx)

    <%@ MasterType VirtualPath="~/Master/Site.master" %>
    

    then you can use the code Brian suggested:

    GridView grid = this.Master.FindControl("GridView1");
    

    Edit: If you want to use the gridview from within another class in the same file i would use the following: Add this to the class created when you make the page

     public partial class YourPageName: System.Web.UI.Page
     {
        public static Gridview mygrid = this.GridviewnameOFYourASPX
        ...
     }
    

    And to your custom class add this in your method

    YourPageName.mygrid.(The changes you want to make);
    

提交回复
热议问题