ObjectDataSource - How do I get at the returned data? (Not using a gridview)

I

Ian

Hiya,

Hope this isn't too stupid a question :)

I can bind an objectdatasource to a gridview very easily (and there's a
thousand tutorials of this on the net).

BUT!

I just want to get at the data so I can say put it in a label.text, or
similar. I've set an objectdatasource up that gets one record from my table,
representing a customer, and I just want to for example to display the
customer name somewhere on the page (other than via a gridview). I think I
was hoping for some sort of MyObjectDataSource.Table property so that I
could start getting at the returned values.

Please help! I'm sure it's ridiculously easy but it's not obvious to little
old me who until now thought .net 2 was looking oh so shiny.

Thanks a lot!

Ian
 
J

John

The Selected event can be used for this:

protected void ActionsDataSource_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
dt = (ObjDataSet.ActionseDataTable) e.ReturnValue;

foreach (xx in dt)
{
}
}

But this result doesn't have the FilterExpression applied (it's the
datatable, not the dataview). dt.DefaultView doesn't work either, so if
anyone knows how to access the filtered results let me know!

I think you can also manually bind the objectdatasource, that way calling
your business object yourself, and manipulating the resultant dataset before
binding.

John
 
A

Andrew Robinson

In general, the new data source controls (object, sql & xml) are designed to
work with the new data presentation controls (gridview, detailsview,
formsview). There is no way to directly bind a "naked" label control to a
ODS but you can wrap it within a formsView:

<asp:FormView ID="FormView1" runat="server"
DataSourceID="ObjectDataSourceMain" AllowPaging="True">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("LocationCode")
%>' />
</ItemTemplate>
</asp:FormView>

You may or may not need paging depending on the number of records returned
by your data object.

Hope this helps,
 

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,020
Latest member
GenesisGai

Latest Threads

Top