【问题标题】:How to change databind using dropdownlist inside gridview?如何使用gridview中的下拉列表更改数据绑定?
【发布时间】:2017-02-23 15:06:15
【问题描述】:

如何根据 gridview 中的下拉列表 selectedvalue 更改数据绑定?我已经尝试使用字符串并且它可以工作,我如何更改选定行上的数据表?

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    您可以像这样使用 GridViewRowDataBound 事件来做到这一点。

    protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Try This
               DropDownlist ddl =((DropDownList)e.Row.FindControl("ddlUOM"));
               Label lblCargo = ((Label)e.Row.FindControl("lblNameOfCargo"));
               if(ddl.SelectedValue == "Barrel")
               {
                 lblCargo.Text = "test";
               }    
            }
        }
    

    【讨论】:

    • 谢谢,但是如何更改 ddl 已更改的行的数据绑定?
    • 你想通过ddl的变化来改变gridview的数据吗?
    • 是的,并且 ddl 在 gridview 中。我想要一些与 ddl 位于同一行的数据根据​​ ddl 选择的值进行更改..
    【解决方案2】:

    在 ddl 的选定索引更改事件上尝试这样的操作。

    DropDownList ddlUOM = (DropDownList)sender;
    GridViewRow rpItem = ddlUOM .NamingContainer as GridViewRow;
    Label lblCargo = ((Label)rpItem.FindControl("lblNameOfCargo"));
    if(ddlUOM.SelectedValue == "Barrel")
      {
        lblCargo.Text = "test";
      }    
    

    【讨论】:

      猜你喜欢
      • 2012-02-09
      • 1970-01-01
      • 2020-12-12
      • 2015-08-15
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多