在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;
}
}
}
?
轉載于:https://www.cnblogs.com/ZkbFighting/p/8628404.html
總結
以上是生活随笔為你收集整理的在gridview里查找模板里的button控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JS 查看标签下某元素所有信息(查看元素
- 下一篇: windows下,‘nmake‘不是内部