2017-02-22 42 views

回答

0

你可以用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"; 
      }  
     } 
    } 
+0

谢谢,但我该如何更改ddl已更改的行的数据绑定? – patrixx

+0

你想通过ddl的改变来改变gridview的数据吗? – SamadRazzak

+0

是的,ddl在gridview中。我想要根据ddl选择的值改变ddl在同一行的一些数据。 – patrixx

0

对选定索引更改ddl事件尝试类似这样的事情。

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