0

当运行包含以下代码的 asp.net 页面时,我得到“DataBinding:'System.Data.DataRowView' 不包含名为 'PKComplexID' 的属性”错误

<asp:TemplateField HeaderText="Complex">
    <EditItemTemplate>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:RefahiConnectionString1 %>"
             SelectCommand="SELECT [PKComplexID], [ComplexName] FROM RFH_Complex">
        </asp:SqlDataSource>
        <asp:DropDownList ID="DDLComplex" runat="server" DataTextField="ComplexName" DataValueField="PKComplexID"
            SelectedValue='<%# Bind("PKComplexID") %>' DataSourceID="SqlDataSource2">
        </asp:DropDownList>
    </EditItemTemplate>
    <ItemTemplate>
         <asp:Label ID="Label" runat="server" Text='<%# Bind("ComplexName") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

它出什么问题了?

4

1 回答 1

1

Don't declare the datasource control inside of the template; the DropDownList won't be able to find a datasource control with a matching ID.

Move the datasource control outside of the grid, and you should be all set.

于 2012-05-07T18:58:28.027 回答