Solved

FormView - After update goes to wrong record

Posted on 2006-07-21
9
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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