views:

316

answers:

1

I have a GridView that I would like to bind to an ObjectDataSource. I have a ReadOnlyCollection of business objects that have many properties. I only to need to display four of these properties in the GridView. I haven't used the ObjectDataSource control before, so how can I use it to display 4 properties of all of the business objects in my ReadOnlyCollection?

+1  A: 

Say you had a list of objects with two properties: Name & Age:

<asp:GridView ID="gvwExample" runat="server" AutoGenerateColumns="False" 
  DataSourceId="myObjectDataSource">
  <columns>
    <asp:BoundField DataField="Name" HeaderText="Name" />
    <asp:BoundField DataField="Age" HeaderText="Age" />
  </columns>
</asp:GridView>

Same thing you would do if you were data binding against any source and didn't want every value of each row of data.

Todd