Data Binding in GridView when using ObjectDataSource

S

SteveM

Hi,

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.
 
L

Ladislav Mrnka

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
property.

I hope this will help.

Best regards,
Ladislav
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top