Now I have done some research on the MSDN on how to get the controls from a Page. http://msdn.microsoft.com/en-us/library/yt340bh4(v=vs.100).aspx
And I have done research on how to get the page reference from a static context. Access current instance of Page from a static class
But when I try to loop through the list of Page controls it comes up null and no gridview.
Now I need that gridview because I am databinding it to a Datatable I have previously filled with a Database call. The static method I am doing this inside of is a WebMethod so it looks like this:
[WebMethod(EnableSession = true)]
[ScriptMethod]
public static string viewApps(){}
Here is my C# code in my static method
GridView applications = new GridView();
Page masspage = HttpContext.Current.CurrentHandler as Page;
foreach(Control childcontrol in masspage.Controls)
{
if(childcontrol is GridView){
applications = childcontrol as GridView;
}
}
applications.DataSource = dt;
applications.DataBind();
I thought it would be simple, but I guess not so much. If there were a way to get a reference to my GridView based on id that would also be useful.
Here is my asp.net code. It is a page that inherits from a master page.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
<ContentTemplate>
<asp:GridView ID="ApplicationsGridView" runat="server"
AutoGenerateColumns="True" >
<%--Styling and column info omitted --%>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>