我有2个下拉菜单,使用tableAdapters填充,list_model下拉菜单完全依赖于list_make下拉菜单,因为它根据点击的make确定要显示的模型,下面是下拉菜单:
<asp:DropDownList ID="list_make" class="form-control padding" runat="server" AutoPostBack="True" DataSourceID="makeODS" DataTextField="make" DataValueField="ID" onselectedindexchanged="list_make_SelectedIndexChanged" SelectedValue='<%# Bind("makeID") %>'></asp:DropDownList>
<asp:ObjectDataSource ID="makeODS" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="getMakes" TypeName="list_dataTableAdapters.MakesTableAdapter"></asp:ObjectDataSource>
<asp:DropDownList ID="list_model" class="form-control padding" runat="server" AutoPostBack="True" DataSourceID="modelODS" DataTextField="model" DataValueField="ID" SelectedValue='<%# Bind("modelID") %>'>
</asp:DropDownList>
<asp:ObjectDataSource ID="modelODS" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetModelsByMakeID" TypeName="list_dataTableAdapters.ModelsTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="list_make" Name="make_id" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
请注意,这些下拉列表位于我的EditItemTemplate中,当单击编辑按钮时,正确检索了SelectedValue,但是当我在list_make中选择一个新项时,我收到此错误
数据绑定方法(如Eval(),XPath()和Bind()只能在数据绑定控件的上下文中使用
有谁知道我收到此错误的原因?
另外如果它有帮助我在list_make_SelectedIndexChanged事件中有这个代码:
protected void list_make_SelectedIndexChanged(object sender, EventArgs e)
{
var listView = listview_car.Items[0].FindControl("list_model") as DropDownList;
listView.DataBind();
}