I've come to a scenario where I need to databind something only if the user is logged in. To do this I am using the LoginView control to display a Login control when they are not logged in and a GridView control when they are logged in. However, when I databind to the GridView object in the LoginView, nothing ever gets displayed. I have been debugging it and I am databinding it to a DataTable that definitely has data in it, however nothing shows up.
Here is some of the code: if (User.Identity.IsAuthenticated) { ((GridView)LoginView1.FindControl("GridView1")).DataSource = dt; ((GridView)LoginView1.FindControl("GridView1")).DataBind(); }
Is there a particular reason that this should not work? Is it bad practice?