Formview Question

K

keniget

Okay, so I'm a bit new to .NET 2.0 and am still fumbling my way around
it. I've come across the FormView control today and have a question.
Hope you guys can help me out.

the structure of my page is as such:

<formview>
<multiview>
huuuge form
</multiview>
<formview>

I have made 2 pages:

LoanApplication.aspx (for the insert)
EditLoanApplication.aspx (for the edit)

Basically, the transition between insert and edit needs to be seemless
- to the user it's the same page and they click on the 'save' button.

Is there any way of grabbing the ID of the newly created row so I can
stick it in the session and switch pages?

Or better yet, is there an in-built / better way of accomplishing this?

Many thanks in advance.
 
V

vMike

Okay, so I'm a bit new to .NET 2.0 and am still fumbling my way around
it. I've come across the FormView control today and have a question.
Hope you guys can help me out.

the structure of my page is as such:

<formview>
<multiview>
huuuge form
</multiview>
<formview>

I have made 2 pages:

LoanApplication.aspx (for the insert)
EditLoanApplication.aspx (for the edit)

Basically, the transition between insert and edit needs to be seemless
- to the user it's the same page and they click on the 'save' button.

Is there any way of grabbing the ID of the newly created row so I can
stick it in the session and switch pages?

Or better yet, is there an in-built / better way of accomplishing this?

Many thanks in advance.
The way I addressed this was to create a formview with an itemtemplate only.
In the template I have textboxes for input. I have a separate save button
the using the following syntax to find the values of the text boxes. In my
case the text box of the formview had an id of l1,12 etc and ci is a
strongly typed class. I then update the database using the class.

dim fvr as formviewrow = formview1.row
ci as New mgCompanyInfo
ci.CompanyName=(ctype(fvr.findcontrol("l1"),textbox).text)
ci.Heading1=(ctype(fvr.findcontrol("l2"),textbox).text)
etc..
There may be other approaches but this one worked great from my purpose.
Maybe this will work for you.

Mike
 
K

keniget

I have tried using just an ItemTemplate but then I get an error when I
try to set the MultiView inside it - it says Object reference not set
to an instance of an object.

Any ideas as to why that is happening?

I read that VS uses the ItemTemplate for inserts and updates if there
is no insert/edit templates available...

This is driving me nuts.
 
V

vMike

I have tried using just an ItemTemplate but then I get an error when I
try to set the MultiView inside it - it says Object reference not set
to an instance of an object.

Any ideas as to why that is happening?

I read that VS uses the ItemTemplate for inserts and updates if there
is no insert/edit templates available...

This is driving me nuts.

Without seeing any code it is tough to say, but I tried this and it works
fine. Maybe it will help you.


First you need to set up some naming convensions for your views and
textboxes or whatever. like view1 has textbox tbview1box1, view2 has
tbview2box1 etc and use someting like this

Sub ImageButton_Click(sender as object, e as ImageClickEventArgs)
'you may not need this
dim ib as imagebutton = directcast(sender,imagebutton)
dim strCommand as string = ib.commandname

dim fvr as formviewrow = formview1.row
dim i as int32
' note multi is the name of my multiview control
dim intView as int32 =
ctype(formview1.findcontrol("multi1"),multiview).ActiveViewIndex
dim strFindPrefix as string = "tbView" & intView.tostring() & "box"

for i = 1 to fvr.controls.count + 1
dim txt as textbox = ctype(fvr.findcontrol(strFindPrefix &
i.tostring()),textbox)
'now I have the textbox in my control value and can use it to get
value etc.
txt.enabled = bSet
next i
end sub
 
V

vMike

I have tried using just an ItemTemplate but then I get an error when I
try to set the MultiView inside it - it says Object reference not set
to an instance of an object.

Any ideas as to why that is happening?

I read that VS uses the ItemTemplate for inserts and updates if there
is no insert/edit templates available...

This is driving me nuts.
Actual this is a bit better or at least might help a bit more. Again, naming
convention is important. Here I name each view view0, view1, etc

dim fvr as formviewrow = formview1.row
dim ctl as multiview = ctype(formview1.findcontrol("multi1"),multiview)
dim intView as int32 = ctl.ActiveViewIndex
dim strFindPrefix as string = "v" & intView.tostring() & "tb"
dim i as int32
dim ctl2 as view = ctype(ctl.findcontrol("View" &
intView.tostring()),view)
dim intCount as int32 = ctl2.controls.count
for i = 0 to intcount - 1
'or you could use find control here on the view.
dim ctl3 as control = ctl2.controls(i)
if ctl3.gettype().fullname = "System.Web.UI.WebControls.TextBox" then
dim txt as textbox = ctype(ctl3, textbox)
txt.enabled = bSet
end if
next i
 
V

vMike

I have tried using just an ItemTemplate but then I get an error when I
try to set the MultiView inside it - it says Object reference not set
to an instance of an object.

Any ideas as to why that is happening?

I read that VS uses the ItemTemplate for inserts and updates if there
is no insert/edit templates available...

This is driving me nuts.
One other bit of assistance. To change/set the view use the item_created
event of the formview as follows

In your control
OnItemCreated="FormView1_ItemCreated"

in your code

Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As EventArgs)
dim fvr as formviewrow = formview1.row
dim ctl as multiview = ctype(fvr.findcontrol("multi1"),multiview)
ctl.ActiveViewIndex = 1
End Sub
 

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

Similar Threads

Using FormView 0
Formview cannot edit data 0
FormView and Master Page 0
FormView Custom Binding help 0
using formview control 0
LINQ and FormView 0
LINQ and FormView 0
Strange Problem with FormView Control 0

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top