Change FormView.ChangeMode to Edit after Insert

Discussion in 'ASP .Net' started by J055, Aug 9, 2006.

  1. J055

    J055 Guest

    Hi

    I'd like to do the following with the FormView/ObjectDataSource but not sure
    of the best approach.

    1. Change the FormView mode to Edit if a valid QueryString ID exists or
    Insert mode if it doesn't
    2. If in Insert mode then when the form is posted it should get the new ID
    from the inserted record and change the FormView Mode to Edit
    3. The SelectParameters ID must be updated too as it needs to get the new
    record.

    My InsertMethod business object returns the new ID.

    Many thanks
    Andrew
     
    J055, Aug 9, 2006
    #1
    1. Advertising

  2. Hi Andrew,

    1. You can do this by checking the QueryString when the page is first
    loaded (non-postback):

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    string sid = Request.QueryString["ID"];
    if (sid != null)
    {
    FormView1.DefaultMode = FormViewMode.Edit;
    }
    else
    {
    FormView1.DefaultMode = FormViewMode.Insert;
    }
    }
    }

    2. You can handle this in the Inserted event of ObjectDataSource and do a
    redirect to current page with ID appended to the QueryString:

    protected void ObjectDataSource1_Inserted(object sender,
    ObjectDataSourceStatusEventArgs e)
    {
    int id = (int)e.ReturnValue;
    Response.Redirect(Request.Url.ToString() + "?ID=" + id.ToString(),
    true);
    }

    3. You can always provide the SelectPrarameters ID in the Selecting event
    of ObjectDataSource:

    protected void ObjectDataSource1_Selecting(object sender,
    ObjectDataSourceSelectingEventArgs e)
    {
    e.InputParameters["id"] = Request.QueryString["ID"];
    }

    Hope this helps. Please feel free to post here if anything is unclear.



    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Aug 10, 2006
    #2
    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. Trev

    Formview ChangeMode Problem

    Trev, Feb 8, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    614
  2. J055
    Replies:
    5
    Views:
    755
    Walter Wang [MSFT]
    Aug 20, 2007
  3. R Bandeira
    Replies:
    0
    Views:
    424
    R Bandeira
    Sep 6, 2007
  4. rodchar

    formview changeMode

    rodchar, Dec 13, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    520
    rodchar
    Dec 17, 2007
  5. David Thielen

    FormView.ChangeMode(FormViewMode.Edit) not working

    David Thielen, Mar 2, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    682
    David Thielen
    Mar 4, 2007
Loading...

Share This Page