FormView FindControl error

D

David C

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
 
D

David C

David C said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top