If Statement within Formview

Hi,

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.
eusaitdeptAsked:
Who is Participating?
 
strickddConnect With a Mentor Commented:
I think what you're looking for is something like this:

If DirectCast(MyFormView.FindControl("fieldinformview"), TextBox).Text = "New" Then
'Do Something
End If
0
 
eusaitdeptAuthor Commented:
Hi - I've written that code up:

 If DirectCast(FormView1.FindControl("StatusLabel"), TextBox).Text <> "Acc" Then
            Button3.Visible = True
        Else
            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.
  Source=SocManagerAdmin
  StackTrace:
       at SocManagerAdmin.WebForm4.Page_Load(Object sender, EventArgs e) in \\orthus.ucs.ed.ac.uk\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)
  InnerException: 

Open in new window



0
 
eusaitdeptAuthor Commented:
Haha! Fixed it, I was looking for a Label not a TextBox so I've changed the code and it's working now, thanks :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.