当前位置:编程学习 > C#/ASP.NET >>

gridview 模板列事件

   gridview 在编辑状态下。模板列中的dropdownlist 如何触发事件啊?  --------------------编程问答-------------------- //先要找到触发事件的行

  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()事件中写. --------------------编程问答-------------------- 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)  
  {  
    
  }  
  }  
}  
--------------------编程问答-------------------- 使用GridView1_RowCommand
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,