0

I am attempting to use a Details view.

This is my DataSource enter image description here

I am passing it this way.

IEnumerable<DataRow> row = Connection.GetDataTable([sql]).AsEnumerable();

this.dvOrderInformation.DataSource = row;
this.dvOrderInformation.DataBind();

I am binding it like so.

<asp:DetailsView ID="dvOrderInformation" runat="server" Height="50px" Width="100%" AutoGenerateRows="false">
    <HeaderTemplate>
        Order
    </HeaderTemplate>
    <FieldHeaderStyle Width="150px" />
    <Fields>
        <asp:BoundField HeaderText="Order Number:" DataField="OrderID" />
    </Fields>
</asp:DetailsView>

When I try this I get the message.

DataBinding: 'System.Data.DataRow' does not contain a property with the name 'OrderID'.

or

A field or property with the name 'OrderID' was not found on the selected data source.

If I bind this directly to a DataGrid it works fine. Any ideas what I am doing wrong here.

TheMonkeyMan
  • 8,622
  • 8
  • 27
  • 42

2 Answers2

1

You can adjust with

this.dvOrderInformation.DataSource = Connection.GetDataTable([sql]);
this.dvOrderInformation.DataBind();

Nota : it's normal row don't contain column, so he don't find column name

DataField="OrderID" is DataColumn.Name

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
0

Found the solution.

this.dvOrderInformation.DataSource = Connection.GetDataSet([sql]);
this.dvOrderInformation.DataBind()

The Key is that I must use a DataSet and not a DataTable.

TheMonkeyMan
  • 8,622
  • 8
  • 27
  • 42