473,796 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FormView inserted record

I have several forms with formviewa on them.
When a new record is inserted the users want to see the readonly
version of that record.
Default behaviour is to show the first record in the collection.
So if there are 5 entries and the user adds a 6th they want to see the
6th rather than the 1st after it's added.

Changing the criteria for the collection they see is not an option.

My quick and dirty solution is to sort on descending id so the most
recent record is first.
Which is fine until 2 people insert records and one gets to see the
"wrong" one.

A better method looks to be
I can get the record id back out of the stored procedure.
I can see you can navigate to a given formview page.
My problem is working out which page corresponds to the id I get back
out the insert.

Any ideas?

Apr 3 '07 #1
1 2409
On 3 Apr, 14:42, "andy" <a...@lycos.co. ukwrote:
I have several forms with formviewa on them.
When a new record is inserted the users want to see the readonly
version of that record.
Default behaviour is to show the first record in the collection.
So if there are 5 entries and the user adds a 6th they want to see the
6th rather than the 1st after it's added.

Changing the criteria for the collection they see is not an option.

My quick and dirty solution is to sort on descending id so the most
recent record is first.
Which is fine until 2 people insert records and one gets to see the
"wrong" one.

A better method looks to be
I can get the record id back out of the stored procedure.
I can see you can navigate to a given formview page.
My problem is working out which page corresponds to the id I get back
out the insert.

Any ideas?
Now had a little more time to think about it...
All the solutions I could find online to this are no good to me since
I don't want to change the datasource to just the one record the user
inserts.

I just iterate through the pages until I find the one corresponds to
the record just added.
It will very likely be the first one since I sort on decreasing id.
In my business layer I retrieve the id using a return parameter out my
insert stored procedure and stick it in session.
Once I find the record I whip this back out of session so the user can
page etc.

protected void fvw_DataBound(o bject sender, EventArgs e)
{
FormView fvw = (FormView)(send er);
if (fvw.CurrentMod e == FormViewMode.Re adOnly)
{
if (Session["Inserted_I d"] != null)
{
string ID = Convert.ToStrin g( Session["Inserted_I d"]);
Session.Remove( "Inserted_I d");
for (int i = 0; i < fvw.PageCount; i++)
{
if (fvw.DataKey[0].ToString() == ID)
{
// gotcha !
break;
}
else
{
fvw.PageIndex++ ;
Trace.Warn("Nex t page: " +
fvw.DataKey[0].ToString());
}
}
}
}

PS

The closest example I found doesn't work since there's just the one
datakey of the single page selected for formview.
I would guess that there's a datakeys of all of the entries for a
gridview so a slightly different technique possible there.

Apr 11 '07 #2

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

Similar topics

1
2321
by: pete | last post by:
I seem unable to get the FormView with the SqlDataSource control in ASP.NET 2.0 beta 2 to insert into my MySQL 4.11 database corectly. When I run the page and click on the Insert link a SQL insert happens and a record gets inserted into my MySQL table but every field that is inserted is NULL. I have a feeling it I am referancing the values incorrectly with my InsertCommand. Here is the insert command: InsertCommand="insert into...
2
4270
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry for the repost. I'd like to make use of the asp:Wizard control to present a step-by-step guided experience for my user to fill out a complicated data-entry form. I'd like to make use of two-way databinding provided by the asp:FormView control...
1
2589
by: yuchang | last post by:
Hi, Using the FormView control is very efficient. But I want to do some action,like showing a success message or redirect to another page, after inserting, updating and deleting. How do I get these message?
7
4353
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the sqldatasource of the formview. If i put this textboxes outside the table everything works well, but as soon as i put them inside the table (in order to organize the layout in the right way) they doesn't work. They works only as eval() and not bind()...
4
13540
by: Rob | last post by:
Hey all, So.. a simple FormView/SqlDataSource to handle inserting records into a table. The table has a primary key that the user enters (eg DiscountCode). If the user enters a duplicate the database complains about a primary key violation (which is what I want) and an exception is thrown. The OnInserted event of the SqlDataSource provides access to the exception so, presumably, you can provide nice handling for various errors. For...
0
1184
by: Hawk | last post by:
Hello, this is my first post hope to get some good answers. I am using asp.net 2.0 and I am trying to pass the value entered in the formview textbox in insert mode "in this case it is the default mode" to a label or hidden field outside of the formview when the insert button is pushed. Is there a way to do this? The App I am creating using many interrelated tables by forgiegn keys and in this case I need to insert a record in one...
1
6306
by: J055 | last post by:
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
0
1598
by: =?Utf-8?B?UGF1bCBCdXp6YSwgb2xkc3RlciB1c2luZyBuZXcg | last post by:
I'm trying to retrieve the @@identity value of the just-inserted record using a FormView control on an .aspx page. Here's what I have tried..... --change in-line Insert in the SqlDataSource from Text to Stored Procedure --added Insert parameter "AdrID" direction:output to the SqlDataSource --added "AdrId" as an OUT parameter in the Stored Procedure --try to retrieve the "AdrId" in the Inserted Event handler of the SqlDataSource The new...
1
6261
by: =?Utf-8?B?QW5u?= | last post by:
Hello, I am using ASP.net 2.0 and I am using templates in a formview control. After I insert a new record, I want the formview Edit template to display with the NEW record that I just inserted. Is this possible and can someone show me some example code in VB. Thanks for your time! Ann
0
10453
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
10172
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
10003
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
9050
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
6785
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
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
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
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.