ObjectDataSource and GridView - Handling Errors During DataBinding

M

Mythran

We have a class that contains the Fetch/Insert/Update/Delete methods that a
DataObjectSource uses to fetch/insert/update/delete for a GridView control.
The Fetch method accepts a single parameter which is a custom class used for
building a search that is then transformed into SQL based on user-input.

Inside the class containing the Fetch/etc. methods, the Fetch method may
throw an exception because the user didn't enter anything in a search/fetch.
The exception is a custom validation exception that notifies the user that
they are required to enter at least one criteria field in order to perform
the search. Is there an event, method, etc. that I can use on either the
ObjectDataSource or GridView control classes to handle the error and display
a message to the user instead of the page redirecting to the unhandled
exception page?

Thanks,
Mythran
 
A

Allen Chen [MSFT]

Hi Mythran,
Is there an event, method, etc. that I can use on either the
ObjectDataSource or GridView control classes to handle the error and display
a message to the user instead of the page redirecting to the unhandled
exception page?

You can handle the exception in the Selected event handler of
ObjectDataSource. Like below:

protected void ObjectDataSource1_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null) {
//handle exception
e.ExceptionHandled = true;
}
}

Please let me know if it works and feel free to ask if you have additional
questions.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the

support we provide to you. Please feel free to let my manager know what you
think of the level of service provided.

You can send feedback directly to my manager at: (e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-

us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community

or a Microsoft Support Engineer within 2 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. 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/en-

us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mythran

Allen Chen said:
Hi Mythran,


You can handle the exception in the Selected event handler of
ObjectDataSource. Like below:

protected void ObjectDataSource1_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null) {
//handle exception
e.ExceptionHandled = true;
}
}

Please let me know if it works and feel free to ask if you have additional
questions.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the

support we provide to you. Please feel free to let my manager know what
you
think of the level of service provided.

You can send feedback directly to my manager at: (e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-

us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community

or a Microsoft Support Engineer within 2 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. 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/en-

us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

I believe this is what I was looking for. Thank you.

Mythran
 
A

Allen Chen [MSFT]

I believe this is what I was looking for. Thank you.

You're welcome! Thank you for using our Newsgroup Support Service!

Regards,
Allen Chen
Microsoft Online Community Support



=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
=================================================
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top