Issue: I have a gridview
that i to reference. However when i try to reference it i get an error.
Error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
gridname was null.
main.aspx.cs
namespace WebApplication1
{
public partial class About : Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = datagridpopulate.Main("supplier", 0, null);
GridView1.DataSource = dt;
GridView1.DataBind();
}
Weird point: This was working yesterday and i made some changes to clean my code and now i cant figure out what ive changed thats made it stop working
Additional notes:
Ive tried to just print the control as a string to a popup window function i have. (pop_up.main(GridView1.ToString());
) however it still states its null.
I would really appreciate your assistance :)
---- Error narrowed down to:
Okay so this is causing the error:
public static global::System.Web.UI.WebControls.GridView GridView1;
it worked when it was:
protected global::System.Web.UI.WebControls.GridView GridView1;
The issue is i need to access the control from other class files. So it needs to be public static. How do get to keep it public static and also use object reference without the error?