Binding a GridView to a particular table in an ObjectDataSource

  • Thread starter Jeronimo Bertran
  • Start date
J

Jeronimo Bertran

Hello,

I am using a ObjectDataSoruce which populates a dataset with 2 tables.


I then bind a GridView using the DataSourceID property set to the
ObjectDataSource. However, I need to use a particular table in the
resulting dataset. If I set the DataMember property in the GridView I get
an exception because the ObjectDataSource only supports a single view.

Is there any way to bind to the second table of a dataset returned by
OjectDataSource?

Thanks

Jeronimo
 
S

Steven Cheng[MSFT]

Hi Jeronimo,

Welcome to the ASPNET newsgroup.

From your description, I understand you have an ASP.NET 2.0 web page which
contains a GridView control displaying data from an ObjectDataSource
control. And the objectdatasource control's associated data access class
will return a DataSet which contains two datatables, you're wondering how
to make the gridView be able to bound to a specific datatable in the
DataSet rather than always hte default one, correct?

Based on my understanding, if we directly return a DataSet for data access
class(used in objectDataSource control), it will always return the
DefaultView of the default datatable(basically the first one). So what we
need to do is customize the Data Access class(which provide the select,
update .... methods). Is this class also developed by you or can you
directly modify it? If not, you may consider create a wrapper class which
encapsulate it.

In our customized class, we can add an additional parameter for the Select
method, this parameter is used to indicate which datatable to return. Then,
when bound to GridView and used in ObjectDataSource control, we just need
to define an additional paramters (control parameter or querystring or
....). How do you think of this?

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


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



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

You're welcome Jeronimo,

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


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



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

justengland

if you get the default view exception. And you are doing the
ObjectBinding make sure that you do not have the datamember property
set on the Gridview. Having it will cause it to look for a datamember
within your result.

Hope this helps
Justin
 
J

justengland

if you get the default view exception. And you are doing the
ObjectBinding make sure that you do not have the datamember property
set on the Gridview. Having it will cause it to look for a datamember
within your result.

Hope this helps
Justin
 

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,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top