Formview Question

Discussion in 'ASP .Net Web Controls' started by keniget@gmail.com, Jun 21, 2006.

  1. Guest

    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.
    , Jun 21, 2006
    #1
    1. Advertising

  2. vMike Guest

    <> wrote in message
    news:...
    > 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
    vMike, Jun 21, 2006
    #2
    1. Advertising

  3. Guest

    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:

    > <> wrote in message
    > news:...
    > > 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
    , Jun 22, 2006
    #3
  4. vMike Guest

    <> wrote in message
    news:...
    > 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:
    >
    > > <> wrote in message
    > > news:...
    > > > 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
    vMike, Jun 22, 2006
    #4
  5. vMike Guest

    <> wrote in message
    news:...
    > 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:
    >
    > > <> wrote in message
    > > news:...
    > > > 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
    vMike, Jun 22, 2006
    #5
  6. vMike Guest

    <> wrote in message
    news:...
    > 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
    vMike, Jun 22, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CJ Taylor

    2.0 Formview question

    CJ Taylor, Oct 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,423
    Jon Stranger
    Oct 10, 2004
  2. Nate Hekman

    asp.net 2.0, datasource/formview question

    Nate Hekman, Dec 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    480
    bruce barker
    Dec 29, 2004
  3. Jonathan Carter

    FormView inheritance question

    Jonathan Carter, Dec 14, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    484
    Jonathan Carter
    Dec 14, 2005
  4. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    521
    Chris
    May 19, 2007
  5. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    637
    David Thielen
    Jun 16, 2006
Loading...

Share This Page