Ace Troubleshooter
Ace Troubleshooter

Reputation: 1379

Databound Dropdowns showing System.Data.DataRowView instead of items?

I've got 3 dropdownlists on my page, all using the same connection string, which is functional. While the third DDL works, the first two only display System.Data.DataRowView instead of the items from the table. Why? It's not the select command; the table and row names are correct, and even when I substitute the select commands for the working DDLs command, the result is the same. Code below:

The first dysfunctional ddl:

<asp:Panel ID="CustPanel" runat="server" BorderWidth="4px" CssClass="myPanelCss" Width="700px">
    <asp:Label ID="LblCustlist" runat="server" Text="Customer: " />
    <asp:DropDownList ID="DropDownList1" runat="server"  DataSourceID="SqlCustNameSource">
        <asp:ListItem Value="0" Text="Choose Customer" Selected="True"></asp:ListItem>
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlCustNameSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT [CustName] FROM [Customer]"></asp:SqlDataSource>
    <asp:Button ID="BtnCustShow" runat="server"  Text="New Customer" OnClick="BtnCustShow_Click" />
</asp:Panel>

The second dysfunctional ddl:

<asp:Panel ID="BroPanel" runat="server" BorderWidth="4px" CssClass="myPanelCss" Width="700px">
    <asp:Label ID="LblBrolist" runat="server" Text="Broker: " />
    <asp:DropDownList ID="DdlBro" runat="server" DataSourceID="SqlBroNameSource">
        <asp:ListItem Value="0" Text="Choose Customer" Selected="True"></asp:ListItem>
    </asp:DropDownList>
<asp:SqlDataSource ID="SqlBroNameSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT [BroName] FROM [Broker]"></asp:SqlDataSource>
    <asp:Button ID="BtnBroShow" runat="server" Text="New Broker" OnClick="BtnBroShow_Click" />
</asp:Panel>

And the working ddl:

<asp:DropDownList ID="DdlCustState" runat="server"  DataSourceID="SqlDataSource2" DataTextField="State" DataValueField="State" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT [State] FROM [States]">
</asp:SqlDataSource>

As I said, if I make the select command for the first two the same as the third, functional ddl, I still get the same failure. Any ideas?

Upvotes: 0

Views: 2044

Answers (2)

KreepN
KreepN

Reputation: 8598

EDIT: Ignore the info I posted a second ago.

What the poster above is saying is correct. You're DDL's are missing their DataTextField="" DataValueField=""

fields that they use to populate the values in the list itself.

Upvotes: 0

Jeff Machamer
Jeff Machamer

Reputation: 942

You have DataTextField="State" and DataValueField="State" on the one that works but not one the ones that don't.

Upvotes: 4

Related Questions