1

我需要根据gridview的该行中另一列中的文本来限制放置在gridview中模板列中的数据绑定下拉列表中的值。我还希望下拉列表是数据绑定的。显然,这两件事不可能同时发生,因为它会给出数据绑定错误。我认为 .net 会阻止它,因为数据库中可能会出现一个在下拉列表中不存在的有效值。

如何使用下拉菜单或任何其他方法完成此操作。

请帮忙。

4

1 回答 1

1

您可以通过根据在文本框中输入的值过滤要显示的数据来限制数据绑定下拉列表的值,对吗?

在事件 grd_RowDataBound 上放 ff: 测试代码

protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
    TextBox txt = (TextBox)e.Row.FindControl("txt");
    DropDownList cbo = (DropDownList)e.Row.FindControl("cbo");

    if (cbo != null)
    {
        cbo.DataSource = _data.getData(txt.Text); //returns filterered datatable based on txt value
        cbo.DataTextField = "ListName";
        cbo.DataValueField = "ListID";
        cbo.DataBind();
    }
}
于 2009-11-06T05:22:29.773 回答