Solved

FormView - After update goes to wrong record

Posted on 2006-07-21
9
235 Views
Last Modified: 2008-02-01
I've run into this problem a few times, I update something in the FormView that is in the Order By clause of the SQL in the SqlDataAdapter, thus changing the order of the rows.  Then the form view goes to ReadOnly mode at the same index as before the edit, but the record displayed is now whatever is in that spot after the order changed.

Any way to force it to go to the record with the same datakeyname after update?
0
Comment
Question by:whityum
  • 4
  • 3
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17160864
I don't understand the situation that you have described.

Bob
0
 
LVL 7

Author Comment

by:whityum
ID: 17163338
I am trying to find a way to loop through the rows of data and find the right key, and then just set the index to that, but I can't figure it out without loading the data into a datatable with another connection and looping through that.  you'd think you could just set the selected data key.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17163584
Can you show me what you have tried that doesn't work, please?

Bob
0
 
LVL 7

Author Comment

by:whityum
ID: 17167024
I've tried what i've done in the past for other controls, loop through the dataitems or set the datasource equal to the datasource of another dataset or something, but it doesn't have the same properties and methods as other controls
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Author Comment

by:whityum
ID: 17167225
Oh, I missed the don't, I thought you did understand.

I have a formview that is bound to a SqlDataSource, all of the edit, insert, and view code is on the ASPX page and built into the 2 controls, there are SqlParameters in the SqlDataSource that do all of the updating by passing the variables to stored procedures, I haven't written any code.

say it's connected to a datasource with 3 records and it's ordered alphabetically by a column, the records are A, C, and E.

A
C
E

I go into edit mode, and change record C to Z, now the order is

A
E
Z

When you come out of edit mode back to readonly mode it is now showing record E because it seems to go back to the same item index of the formview instead of the same record
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17191433
I have no idea.

Bob
0
 
LVL 7

Author Comment

by:whityum
ID: 17391160
this was my work around if wants to know.

Int32 featureItemID = Convert.ToInt32(e.CommandArgument.ToString());
                  this.featureTypeID = Convert.ToInt32(e.CommandName.ToString());
                  int featureIndex = 0;
                  divReport.Visible = false;
                  sdsFeature.SelectParameters["active"].DefaultValue = "False";
                  sdsFeature.SelectParameters["featureTypeID"].DefaultValue = featureTypeID.ToString();
                  sdsFeature.DataBind();
                  fvFeature.DataBind();
                  DataSourceSelectArguments args = new DataSourceSelectArguments();

                  DataView dv = (DataView)sdsFeature.Select(args);

                  DataTable dt = dv.ToTable();            

                  for(int x = 0; x < dt.Rows.Count; x++){
                        if (dt.Rows[x]["featureItemID"].ToString() == featureItemID.ToString()) {
                              featureIndex = x;
                              break;
                        }                  
                  }

                  fvFeature.PageIndex = featureIndex;            
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 17575775
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I use this extension method? 8 47
asp.net mvc return json 2 54
Windows 10 IIS and Windows Authentication to SQL 21 53
Error in query expression 3 35
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now