pse*_*der 5 asp.net formview drop-down-menu
我的DropDownList表单上有2个控件,第二个使用SelectedValue第一个控件作为其绑定参数之一.
这两种DropDownList控制是在FormView.InsertItemTemplate与SelectedValue结合到属性FormView使用绑定表达式的数据源.
第一次FormView在插入模式下渲染,一切正常.问题是AutoPostBack从第一个开始之后DropDownList,FormView没有(重新)绑定,但是由于ControlParameter第二个DropDownList已经改变,它会绑定(按预期),但是第二个DDL的绑定表达式发生异常,I假设因为该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>
Run Code Online (Sandbox Code Playgroud)
我的问题是:使这项功能有效的最佳方法是什么?是否可以将两个DDL保留在模板中?我宁愿避免使用AJAX工具包或其他客户端解决方案.
当我们在数据绑定控件中使用级联下拉列表时,这是一个问题,DetailsView/FormView并且我已多次遇到它.您必须从第二个下拉列表中删除绑定表达式SelectedValue='<%# Bind("AttorneyID") %>',然后它才会起作用.
其次,如果删除Binding表达式,则必须在FormView ItemInsertingEvent中手动传递值.例如
protected void frmAsset_ItemInserting(object sender, FormViewInsertEventArgs e)
{
eValues["AttorneyID"] = ((DropDownList)((FormView)sender).FindControl("ddlAttorny")).SelectedValue;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8546 次 |
| 最近记录: |