473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2389
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(object sender, EventArgs e)
{
FormView fvw = (FormView)(sender);
if (fvw.CurrentMode == FormViewMode.ReadOnly)
{
if (Session["Inserted_Id"] != null)
{
string ID = Convert.ToString( Session["Inserted_Id"]);
Session.Remove("Inserted_Id");
for (int i = 0; i < fvw.PageCount; i++)
{
if (fvw.DataKey[0].ToString() == ID)
{
// gotcha !
break;
}
else
{
fvw.PageIndex++;
Trace.Warn("Next 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
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...
2
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...
1
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...
7
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...
4
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...
0
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...
1
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...
0
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...
1
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....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.