我在窗体上有2 DropDownList
控件,其中第二个使用第一个SelectedValue
作为其绑定参数之一。在模板控件中实现级联DropDownList绑定
两个DropDownList
控制是在绑定到使用一个绑定表达式的FormView
的数据源一个FormView.InsertItemTemplate
与SelectedValue
性质。
第一次FormView
呈现在插入模式下,一切工作正常。问题是在从DropDownList
开始的AutoPostBack
之后,FormView
没有(重新)绑定,但是由于第二个DropDownList
上的ControlParameter
发生了变化,它会进行绑定(如预期的那样),但绑定表达式
System.InvalidOperationException:第二DDL,我由于
FormView
假定没有对通结合数据绑定方法如eval()函数, 的XPath()和绑定()只能在上下文中使用的数据绑定 控制。
下面是标记:
<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工具包或其他客户端解决方案。
OK等等....然后我需要处理的FormView' .ItemInserting'并手动添加参数?在编辑模式下,同样的问题呢?手动处理初始值和更新值?示例代码为后代将不胜感激。 – pseudocoder
呀,确切地说。你也必须做同样的编辑。 –
我验证了此解决方案的正常工作。谢谢!我有一些类似的想法,但不知道大多数人如何解决这个问题。 – pseudocoder