Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > FormView FindControl error

Reply
Thread Tools

FormView FindControl error

 
 
David C
Guest
Posts: n/a
 
      10-28-2009
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


 
Reply With Quote
 
 
 
 
David C
Guest
Posts: n/a
 
      10-28-2009

"David C" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FormView - FindControl Paul Aspinall ASP .Net 14 08-20-2011 07:02 AM
findcontrol in a formview Mr. SweatyFinger ASP .Net 0 12-01-2006 02:46 AM
Equating one formview to another ?? Dynamic type code? Findcontrol? jobs ASP .Net 0 11-07-2006 05:08 PM
Formview FindControl conversion to c# sck10 ASP .Net 2 08-28-2006 10:56 PM
FindControl in FormView Zarn Bou via DotNetMonster.com ASP .Net 0 03-16-2005 12:06 AM



Advertisments