Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object DataSource and GridView

Status
Not open for further replies.

mbde

Programmer
Mar 14, 2005
55
US
I am new to Asp 2.0 and I am trying to work with the new Object DataSource.

All the examples I have found Update and Insert records directly back to a database. What I am looking for the GridView to be disconnect from the data until all changes are made, using the new features of Asp2.0


I tried to hookup the DataSource alone by

CustomerController cc = new CustomerController();
GridView1.DataSource = cc.GetCustomer();
GridView1.DataBind();

But by doing this I have to hookup the Updates and Delete commands of GridView, and possibly create Item Templates, like in Asp1.0

I have been playing with the Object DataSource, and that is nice because it would hook up those events, but I am having trouble writing the Select, Update, Delete members
What I would like is?

SelectCustomer()
{
//If data already grabbed from database, give back current state of data
//If not init data from Database
}

Update()
{
//Set bit for the current object in the current collection to true
// customer.Updated = true;
}

Delete()
{
//Set bit for the current object in the current collection to true
// customer.Delete = true;
}

The problem I keep running into is how do I get to the collection, that is stored in the GridView DataSource?

I hope this made sence, if not I can try and re-explain
 
What I am looking for the GridView to be disconnect from the data until all changes are made, using the new features of Asp2.0
Web apps are disconnected.

I hope this made sence, if not I can try and re-explain
Yes, please.
 
Yes Web Apps are disconnected.

Let me rephrase, I would like a GridView Control that does not perform a Database hit each time for every update, but insteads keeps all changes local to the DataSource. then I can loop through the Collection object, after a user hits a save button.


All of these examples


plus others all show their Update and Delete methods hitting the database to make the change immeditatly.

I would like to use the ObjectDataSource so that it modifies an in memory object and not a database. The problem I keep running into is how to get to the state of that object after it has been bound to the GridView DataSource.
 
In that case you will have to store your datasource in a location such as ViewState, Session, Application or Cache. Then, retrieve it and perform the update whenever necessary.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
You can make the gridivew have all rows in edit mode.. Then have a button for the user to click to save the info. There you would loop through the rows and run the update for each row.
 
ca8msm:

I was trying to go in that direction, however my controller class is in a seperate project... what refernce can I include so I can get to ViewState (or Session)

The other issue, I belive, is that if I assign
GridView.DataSource = ViewState["Data"];

and the source of the GridView changes, does ViewState["Data"] also reflect that change?

 
HttpContext.Current.Cache(...)
OR
HttpContext.Current.Session(...)

and the source of the GridView changes, does ViewState["Data"] also reflect that change?
No, each time you change the datasource, you have to save it back into Cache or Session.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top