gridview 模板中的数据绑定下拉列表

发布于 2024-08-09 22:40:12 字数 179 浏览 3 评论 0原文

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

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

请帮忙。

I need to limit the values in a data bound drop down placed in a template column in a gridview based on the text in another column in that row of the gridview. I also want the dropdown to be databound. Aparently, these two things are not possible at the same time as it gives a data bind error. I think .net prevents it because there is a likelihood of a valid value appearing in the database which doesnt exist in the drop down.

How can I accomplish this using a drop down or any other method.

Kindly help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朱染 2024-08-16 22:40:12

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

在事件 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();
    }
}

You can limit the value of databound dropdown by filtering the data to be displayed based on the values entered on the textbox right?

On the event grd_RowDataBound put the ff: test code

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();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文