Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 12, 2009 08:03 PM by johnly
Jan 24, 2006 10:12 PM|LINK
Though I have been programming for over 10 years, I am a complete .NET noob. I have been working with GridViews for several weeks and after much blood and tears(literally) I have finally figured out how to use GridViews with ObjectData Sources.
Over the past three weeks several specific problems have cost me 3-4 days to figure out. To organize myself, I typed up a step-by-step instruction manual for creating a GridView page (with an Insert section) using my company's provided ObjectData Sources.
While the following may not be a step-by-step instruciton applicable to your specific situation, there are many little gems that may save you fellow .Net noobs a few days of frustration!
If you disagree with me on how to do something then .. well you are probablty right and I would appreciate you to set me straight!
So here it is in all of it's rawness.
If you have your objects squirreled away in a class library, then it may be hard to get yoru changes to show up in the designer.
Every time a change is made in a class library the changes will
not show up in the design pager until you:
Note: If nothing happens when you press Refresh Schema, then it didn’t work.
This is not uncommon. Recompile the whole project, or delete the files in the Bin folder. Try again.
The GridView accepts objects as rows and will use these objects to display the editable grid. However, (to my
great surprise) when you edit the row and hit “Save” the GridView DOES NOT pass back the actual object. Instead it constructs a new object from scratch and fills in
only the columns explicitly displayed/handled in the GridView.
Therefore a Business-layer object need to receive the infant object/row and beef it up.
You have a collection of records. When instantiated they are quite full with all sorts of meta-data like – date of last change, created-by user. Some of these fields are to be calculated, and some of these fields
are to be sent on a round-trip. Create BIZ methods objects that will take in the infantile object, handle all the columns explicitly. (you can also use the
DataKeyNames property - explained later)
I found it necessary to add actual new properties to the object for columns that require differetn data. It seems that the GridView wants 100% of the data reconcilled before it is handed over. I named them
stuff like BIZ_UserName, and BIZ_WarehouseName
i. Create a Get method
return string based on private data
(don’t forget to check for errors and scrub data)
ii. Create an empty Set statement (GridView crashes otherwise)
i. Turn the column into a template, and close
ii. Edit Binding for the
iii. Change the bound field
i. Make the field into a Template and close –
probably already a template from last step
ii. Open the templates and Delete the input field in the
iii. Create a SQL data object (or whatever you want) - and configure it to pull up the appropriate data for the dropdown
Note: Don’t add the DataObject into the actual template field, add it on the main page so that it can be reused by other dropdowns if needed.
Rename the data object to something meaningful
iv. Drag a Dropdown to the
v. Choose data source for the object
Choose the Value and Display fields
vi. Set the SelectedID
Choose Data Bindings for the DropDown
Set the SelectedValue property to the ID of the previously deleted field
i. Chose Edit Bindings
ii. Bind the Dropdown to the appropriate field
( This one really took me a while to figure out. You’d think that since we are only doing Inserts here, we don’t need to bind to a SelectedID. If you do not bind to the correct field, then your dropdown
will always return 0! )
SELECT '', ''
ORDER BY ProductID
Jan 03, 2009 11:33 AM|LINK
hope if you can put this taturial in articles websites like
http://www.codeproject.com and put it with detailed code & images so it will be more readble and useful.. & just here provide us with a link to it....
nice & helpful taturial, thanks
Jun 17, 2009 11:23 AM|LINK
is it 3-tier arch.??? b'cause object datasource is used in 3-tier arch.
Jun 17, 2009 11:27 AM|LINK
i think you should go to www.asp.net/learn/dataaccess.
Jul 12, 2009 08:03 PM|LINK
Thanks for this useful article. I was searching for this for a long time. it really helped.
Your article and the below article helped me.