[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1351
  • Last Modified:

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?
0
mackeyrj
Asked:
mackeyrj
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now