在gridview里查找模板里的button控件

it2026-08-28  11

这个问题,真是搞了我1天,这次记住他

第一种方法:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {

GridViewRow drv = ((GridViewRow)(((Button)(e.CommandSource)).Parent.Parent)); Button btn1 = drv.FindControl("button3") as Button; btn1.Text = "此订单不可取消"; btn1.Enabled = false;

}

第二种方法:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {

//DataRowView drv = e.Row.DataItem as DataRowView; //System.Web.UI.WebControls.Button btn1 = e.Row.FindControl("button3") as System.Web.UI.WebControls.Button; //foreach (GridViewRow gvr in GridView1.Rows) //{ // Button btn1 = GridView1.FindControl("button3") as Button; // btn1.Text = "此订单已经取消"; // btn1.Enabled = false; //}

 

if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.FindControl("Button3") != null) { Button btn1 = (Button)e.Row.FindControl("Button3"); btn1.Text = "此订单已经取消"; btn1.Enabled = false; } }

}

 

转载于:https://www.cnblogs.com/ZkbFighting/p/8628404.html

相关资源:数据结构—成绩单生成器
最新回复(0)