Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Data Binding in GridView when using ObjectDataSource

Thread Tools

Data Binding in GridView when using ObjectDataSource

Posts: n/a

Say you have a GridView control that is sourcing it's data from an
ObjectDataSource whose select method returns a DataSet. By default, the
first table in the dataset is the bound to the GridView control.

I was wondering if there is a way to indicate (either through the
ObjectDataSource or the GridView) which table should be bound. If the
GridView is bound directly to a DataSet (through its DataSource property) I
can use the DataMember property of the Gridview to name the table I want
bound. Setting the DataMember property, however, throws and exception when
the Gridview is bound to an ObjectDataSource control.

I realize that I could just create a method in my undelying business object
that returns the specific table I want bound and set that method as the
select method of the ObjectDataSouce. I was just wondering, however, if
there is a way to do it so that the business object can return a dataset with
multiple tables and the GridView binds to one other than the first.

Thanks for any data binding insight you may be able to provide.

Reply With Quote
Ladislav Mrnka
Posts: n/a
Hello Steve,

this is not directly possible unless you will implement your own DataSource
control similar to ObjectDataSource. The problem is, that ObjectDataSource is
just frontend of SINGLE ObjectDataSourceView instance. It means the
ObjectDataSource only allows you configuring properties of
ObjectDataSourceView in declarative way. The "View" is what is associated
with DataMember property in GridView and so on when you use ObjectDataSource
you can use only its single view = only one DataMember (i guess it is called
DefautView). The reason for this is that each "View" targets not only Select
method but also Insert, Update and Delete methods to the DataMember. The
general idea behind this architecture is that each DataMember contains
different data objects with different structure so you can hardly generalize
these methods to accept all of them.

If you want to only select data from DataSet (without any modification of
data) you shoud bind return value of your business method directly to
DataSource property of GridView in code behind and call DataBind on GridView
(you will not use ObjectDataSource). This will allow you to use DataMember

I hope this will help.

Best regards,
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView - ObjectDataSource - Data Binding =?Utf-8?B?UGhpbGlw?= ASP .Net 2 10-24-2006 03:00 PM
Binding a GridView to a particular table in an ObjectDataSource Jeronimo Bertran ASP .Net Datagrid Control 5 04-11-2006 11:43 PM
Binding tables interesection with GridView/ObjectDataSource [newbie] H5N1 ASP .Net 0 03-27-2006 03:34 AM
Binding tables interesection with GridView/ObjectDataSource [newbie] H5N1 ASP .Net Datagrid Control 0 03-27-2006 03:06 AM
Data Binding - using inline code vs. functions vs. straight binding Jordan ASP .Net 2 02-10-2004 08:32 PM