DropDownList binding get Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据绑定控件异常的上下文中使用

DropDownList binding get Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control exception

我快被这个问题搞疯了... 我有一个用户控件,它有一个用于插入操作的 FormView 和一个用于所有其他操作的 GridView。

在两个控件中,我都有一个 DropDownList,如下所示:

<asp:DropDownList ID="DropDownList" runat="server"
    DataSourceID="ObjectDataSource" 
    DataTextField="Text"
    SelectedValue='<%# Bind("Code") %>'
    DataValueField="Code"
    AppendDataBoundItems="True" Width="200px" />

如果 FormView 中的 DropDownList 存在,主题中的错误就会出现,如果我评论它,GridView 中的 DropDownList 工作完美!它在编辑模式下绑定并更新值没有任何问题!

但它们是一样的,只是 ID 发生了变化。

有趣的是,我还有另一个具有相同控件的页面...

有人知道吗?

谢谢

更多细节:

没有 SelectedValue 属性 页面加载但是当我尝试插入新数据时我得到一个空异常

其他详情:

<asp:Panel ID="PanelInsertPortfolio" runat="server">
    <asp:FormView ID="FormView" runat="server" DefaultMode="Insert" DataSourceID="ObjectDataSourceForm">
        <InsertItemTemplate>
            <asp:Table runat="server">
                <asp:TableHeaderRow>
                    <asp:TableHeaderCell Text="Column 1" />
                    <asp:TableHeaderCell Text="Column 2" />
                    <asp:TableHeaderCell Text="Column 3" />
                </asp:TableHeaderRow>
                <asp:TableRow>
                    <asp:TableCell>
                        <%-- TextBox with server side validators --%>
                    </asp:TableCell>
                    <asp:TableCell>
                        <%-- TextBox with server side validators --%>
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:DropDownList ID="DropDownList" runat="server" DataSourceID="ObjectDataSourceDropDownList" 
                            DataTextField="Name" SelectedValue='<%# Bind("Code") %>' DataValueField="Code" AppendDataBoundItems="True" Width="200px">                        
                        </asp:DropDownList>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server"
                            ControlToValidate="DropDownList" ValidationGroup="ValGroup"
                            ErrorMessage="Required" Display="Dynamic" ForeColor="Red" />
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:ImageButton ID="ImageButton" runat="server" CausesValidation="True"
                            ValidationGroup="ValGroup" CommandName="Insert"
                            ImageUrl="Image.png" />
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
        </InsertItemTemplate>
    </asp:FormView>
</asp:Panel>

<asp:ObjectDataSource ID="ObjectDataSourceDropDownList" runat="server" SelectMethod="GetDataByName"
    TypeName="BLProject.BusinessLogic, BLProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1dd7d67e2859f7d9">
</asp:ObjectDataSource>

FormView 已绑定到另一个 ObjectDataSource。 用户控件在 SharePoint 2013 上运行。

我试图为插入操作放置另一个 ObjectDataSource,我不知道为什么,它起作用了!