我有2个DropDownList
我的表单上的控件,其中第二个使用SelectedValue
第一个作为其绑定参数之一。
Both DropDownList
控件位于FormView.InsertItemTemplate
with SelectedValue
绑定到的属性FormView
使用绑定表达式的数据源。
第一次FormView
在插入模式下渲染,一切正常。问题是在AutoPostBack
从一开始DropDownList
, the FormView
不(重新)绑定,但是由于ControlParameter
在第二个DropDownList
已更改,它确实绑定(按预期),但第二个 DDL 的绑定表达式发生异常,我假设因为FormView
对该通行证没有约束力:
System.InvalidOperationException:数据绑定方法,例如 Eval()、
XPath() 和 Bind() 只能在数据绑定的上下文中使用
控制。
这是标记:
<InsertItemTemplate>
.
.
.
<tr class="GridViewRowB">
<td class="GridViewCell">
Offense Type
</td>
<td class="GridViewCell">
<asp:DropDownList ID="ddlOffenseType" runat="server" DataSourceID="dsOffenseType"
AutoPostBack="true" DataValueField="OffenseTypeID" DataTextField="Description"
SelectedValue='<%# Bind("OffenseTypeID") %>'>
</asp:DropDownList>
<asp:ObjectDataSource ID="dsOffenseType" runat="server" TypeName="OffenseType"
SelectMethod="GetAll">
<SelectParameters>
<asp:Parameter Name="ActiveOnly" DefaultValue="True" Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
<tr class="GridViewRowA">
<td class="GridViewCell">
Attorney
</td>
<td class="GridViewCell">
<asp:DropDownList ID="ddlAttorney" runat="server" DataSourceID="dsAttorney" DataValueField="AttorneyID"
DataTextField="AttorneyNameWithCount" SelectedValue='<%# Bind("AttorneyID") %>'>
</asp:DropDownList>
<asp:ObjectDataSource ID="dsAttorney" runat="server" TypeName="Attorney"
SelectMethod="GetAttorneyWithCaseCount">
<SelectParameters>
<asp:Parameter Name="ActiveOnly" DefaultValue="True" Type="Boolean" />
<asp:ControlParameter Name="OffenseTypeID" Type="Int32" ControlID="ddlOffenseType"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
.
.
.
</InsertItemTemplate>
我的问题是:使此功能发挥作用的最佳方法是什么?是否可以将两个 DDL 保留在模板内?我宁愿避免使用 AJAX 工具包或其他客户端解决方案。
当我们在数据绑定控件中使用级联下拉列表时,这是一个问题DetailsView/FormView
我已经遇到过很多次了。您必须从第二个下拉列表中删除绑定表达式SelectedValue='<%# Bind("AttorneyID") %>'
,然后就可以了。
其次,如果删除 Binding 表达式,则必须在 FormView 中手动传递值ItemInserting
事件。例如
protected void frmAsset_ItemInserting(object sender, FormViewInsertEventArgs e)
{
eValues["AttorneyID"] = ((DropDownList)((FormView)sender).FindControl("ddlAttorny")).SelectedValue;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)