我在formview InsertItemTemplate中有2个下拉列表,我想当我在下拉列表A中更改selectedindex时,下拉列表B将会更改。 我在下拉列表A中更改selectedindex时出错:“数据绑定方法,如Eval(),XPath()和Bind()只能在数据绑定控件的上下文中使用。”
我被困在这里一个小时,任何人都有想法。
这里是我的设计代码:
<asp:Label ID="lblClass" runat="server" Text="Class:"></asp:Label>
<asp:DropDownList ID="cboClass" runat="server" AutoPostBack="true" Width="100%" DataSourceID="sdsClass" DataTextField="ClassName" DataValueField="ClassID" OnSelectedIndexChanged="cboClass_SelectedIndexChanged"></asp:DropDownList>
<asp:Label ID="lblStudent" runat="server" Text="Student Name:"></asp:Label>
<asp:DropDownList ID="cboStudent" runat="server" SelectedValue='<%#Bind("StudentID") %>' Width="100%" DataSourceID="sdsStudent" DataTextField="StudentName" DataValueField="StudentID"></asp:DropDownList>
这里我的代码背后:
protected void cboClass_SelectedIndexChanged(object sender, EventArgs e)
{
sdsStudent.SelectParameters["ClassID"].DefaultValue = (sender as DropDownList).SelectedValue;
(frmExamScore.FindControl("cboStudent") as DropDownList).DataBind();
}