Using FindControl  to find Gridview in LoginView's loggedInTemplate

Posted on 2008-11-14
Last Modified: 2013-11-26
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?
Question by:mackeyrj
    LVL 20

    Accepted Solution

    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


    Expert Comment


    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')

    Author Closing Comment

    Thank you. That worked near perfectly.

    Author Comment

    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.
    LVL 20

    Expert Comment

    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


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now