Grid View and ODS

A

Andrew Robinson

I have a Grid View and associated Object Data Source control. The ODS
interface with a custom data source that returns a List<MyEntity>.

I am only referencing some of the columns on the GridView. When editing a
row within the Grid View, the columns that are not referenced, are being set
to null. Is this by design or am I missing something else somewhere?
 
W

wmain

I have a Grid View and associated Object Data Source control. The ODS
interface with a custom data source that returns a List<MyEntity>.

I am only referencing some of the columns on the GridView. When editing a
row within the Grid View, the columns that are not referenced, are being set
to null. Is this by design or am I missing something else somewhere?

I usually reference all of the columns but set some of them to
invisible. This way they are available in the delete/insert/update
events.
Also make sure you set the 'Set empty values to null' property for
each column to false or empty fields are set to null. Another caveat
to look out for if you are formating the values in display mode. Make
sure you use the Eval and not the Bind method for the data binding.
Otherwise on Delete it tries to convert the formatted values back into
the fields of the objectdatacontrol. This can cause exceptions for
certain currency and numeric formatting.
 
W

Walter Wang [MSFT]

Hi Andrew,

What you're seeing is by design behavior. When a data record is bound to a
row in the GridView, only those referenced fields' values are kept in the
ViewState. To keep them when updating, you will have to bind all the fields
to the GridView and you can selectively hide those columns that you don't
want to show on the page. Another way is to use the primary key to find the
record from your data access layer (or cache) again.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top