473,804 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change FormView.Change Mode to Edit after Insert

Hi

I'd like to do the following with the FormView/ObjectDataSourc e 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 SelectParameter s ID must be updated too as it needs to get the new
record.

My InsertMethod business object returns the new ID.

Many thanks
Andrew


Aug 9 '06 #1
1 6307
Hi Andrew,

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

protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
string sid = Request.QuerySt ring["ID"];
if (sid != null)
{
FormView1.Defau ltMode = FormViewMode.Ed it;
}
else
{
FormView1.Defau ltMode = FormViewMode.In sert;
}
}
}

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

protected void ObjectDataSourc e1_Inserted(obj ect sender,
ObjectDataSourc eStatusEventArg s e)
{
int id = (int)e.ReturnVa lue;
Response.Redire ct(Request.Url. ToString() + "?ID=" + id.ToString(),
true);
}

3. You can always provide the SelectPraramete rs ID in the Selecting event
of ObjectDataSourc e:

protected void ObjectDataSourc e1_Selecting(ob ject sender,
ObjectDataSourc eSelectingEvent Args e)
{
e.InputParamete rs["id"] = Request.QuerySt ring["ID"];
}

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

Regards,
Walter Wang (wa****@online. microsoft.com, 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.

Aug 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3123
by: Random | last post by:
In the ASP.NET 2.0 beta, the FormView control has the ItemTemplate and InsertItemTemplate areas (and others). All the documentation I've found says the way to toggle between the views is to use a control with the appropriate CommandName. But, I want to decide this when the page loads, based on the selection made in a DropDownList on a previous page (basically selecting between a read-only view of an item, an item edit, or a new item)....
4
6184
by: staeri | last post by:
I have a FormView with DefaultMode="Insert". I want to change this to DefaultMode="Edit" with code but this doesn't work. It's still in insert mode. I've used the following code: Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) FormView1.ChangeMode(FormViewMode.Edit) FormView1.DefaultMode = FormViewMode.Edit End Sub
2
2158
by: sck10 | last post by:
Hello, I have a LinkButton that I use to open a FormView in ReadOnly mode "ShowList", and a LinkButton to open the same FormView in the Insert mode "NewRecord". If the user clicks "ShowList" then a GridView opens up and they can then select a record to view the record in the FormView. If they select the "NewRecord" LinkButton, the same FormView opens in Insert mode. The problem that I am having is that when the user clicks the...
1
3893
by: scartin | last post by:
I'm fairly new to working with ASP web controls, and am running into what seems to be a ridiculous problem that I'm hoping will be a breeze for an experienced ASP developer. I have a GridView and a FormView on the same page, where the GridView is visible at page load, and the FormView is set to Edit mode by default, but is hidden on the page. I have the Select link enabled on my GridView, and I use the SelectedIndexChanged event to hide...
1
2714
by: Kyle K. | last post by:
I would like to build my data pages such that the top of the page contains a GridView showing the data with 'Enable Select = true'. Below that I would like to have a FormView, that by default is in 'Insert' mode for creating a new record. If the user 'selects' a record in the GridView above, I would like to set the FormView to 'Edit' mode with the 'selected' record data loaded in it for editing. I would use the built-in editing...
1
4344
by: Trev | last post by:
Hi, I'm hoping that someone in this group can shed some light on an issue I'm having with a Formview. I have a Web User Control (.ascx) with a Formview. The Formview contains 2 Multiviews, one in the EditItemTemplate and one in the InsertItemTemplate. Each of those Multiviews contains several Views, and each view contains several controls such as textboxes, checkboxes etc. Those controls are bound to the Formview's datasource, which...
1
1746
by: Chris | last post by:
I have a treeview control, which I use to select a row in a table which will be used to populate a formview. Depending on what node is selected in the treeview I want the formview to be either in update or insert mode. Protected Sub tvwmenu_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvwmenu.SelectedNodeChanged ViewState("menuid") = menuid ViewState("parentid") = parentid If menuid <0 Then
5
5356
by: rsdev | last post by:
Hi Guys, I can't get to the bottom of this one. I have a formview in an updatepanel and I switch between ReadOnly and Edit mode. No problem the first time round but when I try on the second go to return to ReadOnly it sticks in Edit mode. Wierd!!! Here's my code; public void BtnCloseEditMode_Click(object sender, EventArgs args) {
4
8570
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that when it displays it shows values from the database and i have a link button edit on the ItemTemplate that changes the mode to edit mode and allows to edit the values which can be edited...
0
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.