FormView FindControl error

Discussion in 'ASP .Net' started by David C, Oct 28, 2009.

  1. David C

    David C Guest

    I have a FormView that is in an aspx page with a Master Page. I am trying
    to show or hide 2 controls based on a condition. Below is part of the
    DataBound event code that I am having a problem with.

    Protected Sub fvActivityHistory_DataBound(ByVal sender As Object, ByVal
    e As System.EventArgs) Handles fvActivityHistory.DataBound
    Dim row As FormViewRow = fvActivityHistory.Row
    Dim tb As TextBox
    Dim ddl As DropDownList
    Dim lbl As Label

    If fvActivityHistory.CurrentMode = FormViewMode.Insert Then
    ....bunch of code here....

    ElseIf fvActivityHistory.CurrentMode = FormViewMode.Edit Then
    tb = Page.Master.FindControl("txtProgramID")
    If tb.Text = "4" Then
    'FAP Rep Payee so show units to bill
    tb = row.FindControl("txtUnits")
    tb.CssClass = "Show"
    lbl = row.FindControl("LblUnits")
    lbl.CssClass = "Show"
    Else
    End If
    End If
    End Sub

    I am getting the error

    Object reference not set to an instance of an object.

    It is happening on the tb = row.FindControl("txtUnits") line. Should I do
    something more in the FindControl if the FormView is inside a
    ContentPlaceHolder? Thanks.

    David
     
    David C, Oct 28, 2009
    #1
    1. Advertising

  2. David C

    David C Guest

    "David C" <> wrote in message
    news:%...
    >I have a FormView that is in an aspx page with a Master Page. I am trying
    >to show or hide 2 controls based on a condition. Below is part of the
    >DataBound event code that I am having a problem with.
    >
    > Protected Sub fvActivityHistory_DataBound(ByVal sender As Object, ByVal
    > e As System.EventArgs) Handles fvActivityHistory.DataBound
    > Dim row As FormViewRow = fvActivityHistory.Row
    > Dim tb As TextBox
    > Dim ddl As DropDownList
    > Dim lbl As Label
    >
    > If fvActivityHistory.CurrentMode = FormViewMode.Insert Then
    > ....bunch of code here....
    >
    > ElseIf fvActivityHistory.CurrentMode = FormViewMode.Edit Then
    > tb = Page.Master.FindControl("txtProgramID")
    > If tb.Text = "4" Then
    > 'FAP Rep Payee so show units to bill
    > tb = row.FindControl("txtUnits")
    > tb.CssClass = "Show"
    > lbl = row.FindControl("LblUnits")
    > lbl.CssClass = "Show"
    > Else
    > End If
    > End If
    > End Sub
    >
    > I am getting the error
    >
    > Object reference not set to an instance of an object.
    >
    > It is happening on the tb = row.FindControl("txtUnits") line. Should I do
    > something more in the FindControl if the FormView is inside a
    > ContentPlaceHolder? Thanks.
    >
    > David
    >


    Nevermind. I was binding the control when it was hidden.
    David
     
    David C, Oct 28, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zarn Bou via DotNetMonster.com

    FindControl in FormView

    Zarn Bou via DotNetMonster.com, Mar 16, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    2,936
    Zarn Bou via DotNetMonster.com
    Mar 16, 2005
  2. Paul Aspinall

    FormView - FindControl

    Paul Aspinall, Feb 25, 2006, in forum: ASP .Net
    Replies:
    14
    Views:
    38,881
  3. sck10
    Replies:
    2
    Views:
    5,077
    sck10
    Aug 28, 2006
  4. jobs
    Replies:
    0
    Views:
    425
  5. Mr. SweatyFinger

    findcontrol in a formview

    Mr. SweatyFinger, Dec 1, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    468
    Mr. SweatyFinger
    Dec 1, 2006
Loading...

Share This Page