GridView动态绑定事件及判断数据所在行

在GridView的RowDataBound事件时触发:
protected void gvCity_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton ib = (ImageButton)e.Row.FindControl("imgbtneditor");
string id = ib.CommandArgument.ToString();
ib.Attributes.Add("onclick", "update('update','" + id + "')");

}
}
判断数据所在行
 protected void btnChange_Click(object sender, EventArgs e)
{

Button btn=(Button)sender;//转换成sender
string summaryNid = btn.CommandArgument.ToString();
//获得控件所在GridView所在行数
int index = (btn.NamingContainer as GridViewRow).RowIndex;
DropDownList ddlHeadTeacher = (DropDownList)gvApply.Rows[index].FindControl("ddlHeadTeacher");

}



原文地址:https://www.cnblogs.com/pigddyou/p/2302310.html