Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Change FormView.ChangeMode to Edit after Insert

Reply
Thread Tools

Change FormView.ChangeMode to Edit after Insert

 
 
J055
Guest
Posts: n/a
 
      08-09-2006
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




 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      08-10-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to keep values in fields after ChangeMode to Insert from Edit? R Bandeira ASP .Net 0 09-06-2007 09:33 PM
Need better run/edit method. I have to restart the shell after every script change. Mark Python 3 01-12-2007 04:19 PM
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM
Set the width of the edit textbox after clicking on Edit link in datagrid... Sharon McCarty ASP .Net Datagrid Control 0 11-24-2004 06:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57