FormView out of sync

F

flodpanter

I have one objectdatasource which both a gridview and a formview rely
on.

In my Gridview I have a command button which should display the
selected row in my formview.

Sorting the gridview doesnt effect the formview. The formview still
uses the original order by which my records are stored. How can solve
this?
 
C

Cowboy \(Gregory A. Beamer\)

It should be working with the DataKeyName(s) without issue, as long as you
set the DataKeyName(s). If this is not working, there are a couple of ways
to "fake" this. One is to add a button column (can be a link button rather
than a true button) and tack an ID to the event args. Thsi is a bit more
programming, but ties to data instead of row position. Anotehr is to have a
postback via a hyperlink column. The downside here is info coming up on the
querystring (not a problem in most applications, but it can have
consequences in others, esp. if the grid still has to show (as viewstate is
cleared with a GET)). As long as you do not have to display both Grid and
form at the same time, however, this works. If you have to reconstitute the
grid exactly as left, you will have to store some pointers in session or
cache to restore when you pull data on the next hit.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
 
F

flodpanter

I have set the DatakeyNames in both GV and FV to the same id value.
Do I have to do further coding in the Gridviews sorted event to make it
work?
 
Joined
Nov 2, 2006
Messages
1
Reaction score
0
FormView GridView out of sync problem

After hours of pulling my hair, a lot of bad language and searching on the web
I have come up with a solution that seems to work.
First of all, forget about indexes. The formview control does'nt seem to alter it's pageindex, even after a databind().
You need two objectdatasources. With just one you end up trying to find the correct dataitem in the formview, which you can't do. (At least I cant figure out how to do it)

The formviewObjectDatasource is set to point at a getSomeObjectById(string id) method. Which returns a singel object. The gridviewObjectDatasource points at the getSomeObjects() method.
Then you get the id from the gridviews selectedValue parameter, this is set in the datakey.

Problem: If the formview is databinded before the gridview you end up with a nullreference on the id parameter.
Solution to this is calling gridview.DataBind() as the first thing you do in page_Load. That is not the most beautiful solution, but I dont know any other way to be sure the gridview binds first..

The formview can now display a row selected from the gridview after sorting.

This solution is neither beautiful nor effective, but it works.

If you have found any other solution, please let me know
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top