Main Page | Report this Page
.NET DotNet Forum Index  »  ASP.NET Forum  »  FormView FindControl error...
Page 1 of 1    

FormView FindControl error...

Author Message
David C...
Posted: Wed Oct 28, 2009 4:19 pm
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...
Posted: Wed Oct 28, 2009 4:27 pm
Guest
"David C" <dlchase at (no spam) lifetimeinc.com> wrote in message
news:%23jGBfzBWKHA.5208 at (no spam) TK2MSFTNGP05.phx.gbl...
Quote:
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
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Fri Dec 11, 2009 10:58 am