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

标签 c# asp.net drop-down-menu binding bind

这个问题我快疯了... 我有一个用户控件,它有一个用于插入操作的 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 工作得很好!它在编辑模式下绑定(bind)并更新值没有任何问题!

但它们是一样的,只是 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 已绑定(bind)到另一个 ObjectDataSource。 用户控件在 SharePoint 2013 上运行。

最佳答案

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

关于c# - DropDownList binding get Eval()、XPath() 和 Bind() 等数据绑定(bind)方法只能在数据绑定(bind)控件异常的上下文中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30850415/

相关文章:

c# - Windows Azure REST API SharedKeyLite 身份验证(存储模拟器)

c# - Asp.net 开源项目作为 c# 中的学习资源

search - 在SHOPIFY中添加 "items per page"下拉框

c# - 下拉列表中的图像

c# - WCF Contract 继承的契约(Contract)

c# - 重载 == (当然还有 != )运算符,我可以绕过 == 来判断对象是否为 null

c# - 应用程序是否需要对父文件夹的写权限?

Java-调用.net wcf web服务Spring

c# - 无法使用 ActionLink 打开模态弹出窗口

html - 如何将 li 菜单与下拉菜单水平对齐