开发者

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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜