Home All Groups Group Topic Archive Search About
Author
21 Jun 2006 1:52 PM
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.

Author
21 Jun 2006 5:31 PM
vMike
<keni***@gmail.com> wrote in message
Show quoteHide quote
news:1150897929.174714.274170@y41g2000cwy.googlegroups.com...
> 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
Author
22 Jun 2006 9:10 AM
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.

vMike wrote:

Show quoteHide quote
> <keni***@gmail.com> wrote in message
> news:1150897929.174714.274170@y41g2000cwy.googlegroups.com...
> > 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
Author
22 Jun 2006 5:47 PM
vMike
<keni***@gmail.com> wrote in message
Show quoteHide quote
news:1150967403.212514.123160@r2g2000cwb.googlegroups.com...
> 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.
>
> vMike wrote:
>
> > <keni***@gmail.com> wrote in message
> > news:1150897929.174714.274170@y41g2000cwy.googlegroups.com...
> > > 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:

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
Author
22 Jun 2006 8:05 PM
vMike
<keni***@gmail.com> wrote in message
Show quoteHide quote
news:1150967403.212514.123160@r2g2000cwb.googlegroups.com...
> 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.
>
> vMike wrote:
>
> > <keni***@gmail.com> wrote in message
> > news:1150897929.174714.274170@y41g2000cwy.googlegroups.com...
> > > 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>
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
Author
22 Jun 2006 8:46 PM
vMike
<keni***@gmail.com> wrote in message
news:1150967403.212514.123160@r2g2000cwb.googlegroups.com...
> 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