gridview 在编辑状态下。模板列中的dropdownlist 如何触发事件啊? 

解决方案 »

  1.   

    //先要找到触发事件的行  GridViewRow editRow = (GridViewRow)((Control)sender).Parent.Parent;//然后找到控件        DropDownList ddl = (DropDownList)(editRow.FindControl("dropdownListName"));
           TextBox txt = (TextBox)(editRow.FindControl("textBoxName"));//再赋值:
            txt.Text = ddl.SelectedItem.Text;把DropDownList的AutoPostBack属性设置为true; 
    然后在SelectedIndexChange()事件中写.
      

  2.   

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)  
    {  
    if (e.Row.RowType == DataControlRowType.DataRow)  
    {  
    if (e.Row.FindControl("DropDownList1") != null)  
    {  
    DropDownList ddl =e.Row.FindControl("DropDownList1") as DropDownList;  
    ddl.DataSource = ds;  
    ddl.DataBind();   
    }  
    }  
    }  
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)  
    {  
      GridViewRow gvr = (sender as DropDownList).NamingContainer as GridViewRow;  
      if(gvr != null)  
      {  
      DropDownList ddl = gvr.FindControl("DropDownList1") as DropDownList;  
      if(ddl != null)  
      {  
        
      }  
      }  
    }