Using FindControl to find Gridview in LoginView's loggedInTemplate

It seems like it should be very simply and staight fforward, but I can figure it out.
I want to fill a gridview with info frrom a dataset for an authenticated user.
I put the gridview in the loggedintemplate of a loginview, but now I can't find it.
What is the proper way to use findcontrol in this situation?
mackeyrjAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Juan_BarreraCommented:
Hi there,
Can you please try the following:

Dim gv As GridView
If HttpContext.Current.User.Identity.IsAuthenticated Then
 Dim gv As GridView = CType(LoginView1.FindControl("GridViewId"),GridView)
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lorgeronCommented:
Hi!

Have you tried like this:
GridView GridView1 = (GridView)this.LoginView1.FindControl("GridView1");

Be aware, that you can only access controls, that are in the currently active template. You cannot access anything in the LoggedInTemplate, if no user is logged in.

(I hope i was clear, this is my first advice as an 'expert')
0
mackeyrjAuthor Commented:
Thank you. That worked near perfectly.
0
mackeyrjAuthor Commented:
You dimmed gv twice which was a minor problem. I removed the first one and changed the GridViewID to match the name of my Gridview.
0
Juan_BarreraCommented:
Yeah, sorry about that, just fast typing. I'm glad it helped otherwise. It should've been:

Dim gv As GridView
If HttpContext.Current.User.Identity.IsAuthenticated Then
  gv = CType(LoginView1.FindControl("GridViewId"),GridView)
End If

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.