If Statement within Formview

Posted on 2011-10-18
Last Modified: 2013-11-26

Looking to write a very simple if statement that would read something like this:

If fieldinformview = "New" then
  cmdAccept.Visible = True
End If

I can't currently find a function that will allow me to pull out the formview's data so that the statement will work.

Help much appreciated.
Question by:eusaitdept
    LVL 28

    Accepted Solution

    I think what you're looking for is something like this:

    If DirectCast(MyFormView.FindControl("fieldinformview"), TextBox).Text = "New" Then
    'Do Something
    End If

    Author Comment

    Hi - I've written that code up:

     If DirectCast(FormView1.FindControl("StatusLabel"), TextBox).Text <> "Acc" Then
                Button3.Visible = True
                Button3.Visible = False
            End If

    Open in new window

    However receive the following error on loading the page:

    System.NullReferenceException was unhandled by user code
      Message=Object reference not set to an instance of an object.
           at SocManagerAdmin.WebForm4.Page_Load(Object sender, EventArgs e) in \\\eusahome\abyers1\Visual Studio 2010\Projects\SocManagerAdmin(7)\SocManagerAdmin\pages\devDetails.aspx.vb:line 7
           at System.Web.UI.Control.OnLoad(EventArgs e)
           at System.Web.UI.Control.LoadRecursive()
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Open in new window


    Author Comment

    Haha! Fixed it, I was looking for a Label not a TextBox so I've changed the code and it's working now, thanks :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 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

    9 Experts available now in Live!

    Get 1:1 Help Now