【问题标题】:Data bound drop down in a gridview template网格视图模板中的数据绑定下拉菜单
【发布时间】:2009-11-05 18:43:51
【问题描述】:

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

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

请帮忙。

【问题讨论】:

    标签: gridview drop-down-menu limit databound


    【解决方案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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      • 2019-03-13
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多