在gridview里查找模板里的button控件
这个问题,真是搞了我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; } } }
人各有命,上天注定,有人天生为王,有人落草为寇。脚下的路,如果不是你自己的选择,那么旅程的终点在哪,也没人知道。你会走到哪,会遇到谁,都不一定。