gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:39:01 28 4
gpt4 key购买 nike

这个问题我快疯了...我有一个用户控件,它有一个用于插入操作的 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com