0

我在详细信息视图的两个不同字段中有两个下拉列表,第一个确定第二个的值。

当我从第一个 ddl 自动回发中选择一个值时,会删除详细信息视图中已经存在的所有数据并将第一个下拉列表恢复为第一个选择。

此外,当我从列表中选择(多次更改 ddl 选择)时,它会抛出:

Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据绑定控件的上下文中使用。

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.InvalidOperationException:Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据绑定控件的上下文中使用。

源错误:

[没有相关的源代码行]

------First DDL

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SQLLEAVECODE"
DataTextField="LEAVETYPE" DataValueField="LEAVECODE"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AppendDataBoundItems="True" ViewStateMode="Enabled" AutoPostBack="True"
SelectedValue='<%# BIND("REQLEAVECODE") %>' Width="80px">
<asp:ListItem> </asp:ListItem>
</asp:DropDownList>

-------Second DDL

<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1"
DataTextField="REASON" DataValueField="REASON" 
SelectedValue='<%# Bind("leavetype") %>'>
</asp:DropDownList>



---------page load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DetailsView1.DataBind();
}
}


--------DDL 1 selectedIndexChange
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
Label27.Text = lvtype.SelectedValue.ToString();

DetailsView1.Fields[4].Visible = true;
}
4

2 回答 2

1

如果Drop-downDetailsViewthen 请处理ItemCommand eventofDetailsView而不是DropDownList1_SelectedIndexChanged

希望对你有帮助

于 2012-08-14T04:46:46.037 回答
0

您的标记是指ID="DropDownList1"ID="DropDownList2"

但是,您的事件处理程序指的是DetailsView1.FindControl("DropDownList6")and DetailsView1.FindControl("DropDownList6")。这可能与您的问题有关吗?

于 2012-08-14T05:34:54.827 回答