gpt4 book ai didi

asp.net - 如何在 EditItemTemplate 中自动回发?

转载 作者:行者123 更新时间:2023-12-02 21:28:27 26 4
gpt4 key购买 nike

我在 FormView EditItemTemplate 中有几个 DropDownList。其中一个是经纪人列表,另一个是经纪人账户列表。当经纪商 DropDownList 更改时,我希望用该经纪商的账户列表填充账户 DropDownList。

页面开始如下:

<asp:FormView
ID="fvwEditTrade"
DataSourceID="srcTrade"
runat="server"
DataKeyNames="tradeId"
DefaultMode="Edit"
CssClass="formView"
OnItemUpdated="fvwEditTrade_Updated"
OnItemCommand="fvwEditTrade_Command"
OnItemUpdating="fvwEditTrade_Updating"
>
<EditItemTemplate>
<asp:Label ID="lblTradeId" Text="TradeId: " runat="server" CssClass="label" /><%# Eval("tradeId") %>
<br />

<asp:Label ID="lblBroker" Text="Broker" runat="server" CssClass="label" />
<asp:DropDownList
ID="ddlBrokers"
runat="server"
CssClass="dropdownlist"
DataSourceID="srcBrokers"
DataTextField="broker"
DataValueField="brokerId"
SelectedValue='<%# Bind("brokerId") %>'
AutoPostBack="true"
/>
<br />

<asp:Label ID="lblAccount" Text="Account" AssociatedControlID="ddlAccounts" runat="server" CssClass="label" />
<asp:DropDownList
ID="ddlAccounts"
runat="server"
CssClass="dropdownlist"
DataSourceID="srcAccounts"
DataTextField="description"
DataValueField="accountId"
SelectedValue='<%# Bind("accountId") %>'
/>
<br />

然后我有

   <asp:Button
id="lnkUpdate"
Text="Update"
CommandName="Update" CssClass="button"
Runat="server" />

<asp:Button
id="lnkCancel"
Text="Cancel"
CommandName="Cancel" CssClass="button"
Runat="server" />

</EditItemTemplate>
</asp:FormView>


<CustomControls:CustomObjectDataSource
id="srcTrade"
TypeName="DatabaseComponent.DBUtil"
SelectMethod="GetTrade"
UpdateMethod="UpdateTrade"
runat="server">
<SelectParameters>
<asp:QueryStringParameter Name="tradeId" QueryStringField="tradeId" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter Name="tradeId" ControlId="fvwEditTrade" PropertyName="SelectedValue" />
<asp:ControlParameter Name="accountId" ControlId="fvwEditTrade$ddlAccounts" PropertyName="SelectedValue" />
<asp:ControlParameter Name="symbol" ControlId="fvwEditTrade$ddlSymbols" PropertyName="SelectedValue" />
<asp:ControlParameter Name="riskProfileId" ControlId="fvwEditTrade$ddlRiskProfiles" PropertyName="SelectedValue" />
<asp:ControlParameter Name="pctAccountRisked" ControlId="fvwEditTrade$txtPctAccountRisked" PropertyName="Text" />
<asp:ControlParameter Name="tradeSetupId" ControlId="fvwEditTrade$ddlSetups" PropertyName="SelectedValue" />
<asp:ControlParameter Name="amountPerUnit" ControlId="fvwEditTrade$txtamountPerUnit" PropertyName="Text" />
<asp:ControlParameter Name="initialStopPrice" ControlId="fvwEditTrade$txtInitialStopPrice" PropertyName="Text" />
<asp:ControlParameter Name="tfCode" ControlId="fvwEditTrade$ddlTimeFrames" PropertyName="SelectedValue" />
<asp:ControlParameter Name="MAEPips" ControlId="fvwEditTrade$txtMAEPips" PropertyName="Text" />
<asp:ControlParameter Name="MFEPips" ControlId="fvwEditTrade$txtMFEPips" PropertyName="Text" />
<asp:ControlParameter Name="tradeGrade" ControlId="fvwEditTrade$ddlTradeGrades" PropertyName="SelectedValue" />
<asp:ControlParameter Name="executionGrade" ControlId="fvwEditTrade$ddlExecutionGrades" PropertyName="SelectedValue" />
<asp:ControlParameter Name="comment" ControlId="fvwEditTrade$txtComments" PropertyName="Text" />
</UpdateParameters>
</CustomControls:CustomObjectDataSource>

<CustomControls:CustomObjectDataSource
id="srcBrokers"
TypeName="DatabaseComponent.DBUtil"
SelectMethod="GetBrokers"
runat="server">
</CustomControls:CustomObjectDataSource>

<CustomControls:CustomObjectDataSource
id="srcAccounts"
TypeName="DatabaseComponent.DBUtil"
SelectMethod="GetBrokerAccounts"
runat="server">
<SelectParameters>
<asp:ControlParameter Name="brokerId" ControlId="fvwEditTrade$ddlBrokers" PropertyName="SelectedValue" />
</SelectParameters>
</CustomControls:CustomObjectDataSource>

当页面加载时,我收到此错误:

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

如果我将 CustomObjectDataSources srcBrokers 和 srcAccounts 移动到 EditItemTemplate“内部”,页面加载正常,但是,当我在 ddlBrokers 中选择代理时,我再次收到相同的错误:

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

关于如何解决这个问题有什么想法吗?数据源应该位于 EditItemTemplate 外部还是内部?

最佳答案

删除绑定(bind)表达式 SelectedValue='<%# Bind("accountId") %>'来自 ddlAccounts。这是造成问题的原因。您需要从代码后面处理这个问题。

当尝试更新项目时,您必须传递此下拉列表中的选定值 FormView ItemUpdating Event

关于asp.net - 如何在 EditItemTemplate 中自动回发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6045819/

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