Default edit mode problem

C

Chris

I have a treeview in the edit template of my formview but not in the item
templete. It is populated programatically with the code below. When the
default mode is readonly this code works fine. When I set the default to
edit I get a 'Object reference not set to an instance of an object' on the
line that tries to find the control. The Formview becomes active when a row
is selected in a gridview.

If FormView1.CurrentMode = FormViewMode.Edit Or FormView1.CurrentMode =
FormViewMode.Insert Then
Dim tw As TreeView
tw = New TreeView()
tw = FormView1.Row.FindControl("treeview1")
tw.Nodes.Clear()
GetFolders(Server.MapPath(""), tw.Nodes)
End If

When I set it to readonly it goes into readonly mode it works fine. But
there is no treeview in the read only mode. When I select the edit button it
goes into edit mode and finds the treeview. It is only in the default mode.
Can anyone help? Regards, Chris.
 
C

CaffieneRush

Where are you calling this code from? Page_Load?

It will be safest to call the code above from within the ItemCreated
event handler of the FormView. This way you know that the controls
within the row (HeaderRow, FooterRow, BottomPagerRow) has created.

Regards,
Andy
 
C

Chris

It is getting called from the itemcreated. That's what is confusing me. The
control should have been added.
 
C

CaffieneRush

Very strange, it's almost as if the FormView is not loading the
EditItemTemplate properly when you set the DefaultMode to Edit.

Regards,
Andy
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top