close

接續加入Button後

想依據Button的值來控制是否Enabled &改變字體顏色

在RowDataBound中

加入判斷式

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.DataItem != null)
            {
                foreach (Control cmdControl in ((DataControlFieldCell)e.Row.Cells[4]).Controls)                // 4<---Button 在Gridview 中的位置 從0算起
                {
                    if ((cmdControl) is Button)
                    {
                        Button btn = (Button)cmdControl;
                        if (btn.Text.ToString() != "審核")
                        {
                            btn.Enabled = false;                                              
                        }
                        else
                        {
                            btn.ForeColor = System.Drawing.Color.Blue;                //改變顏色
                        }
                    }
                }
            }
        }
    }

 

 

 

arrow
arrow
    文章標籤
    asp.net GridView
    全站熱搜

    JosephChou 發表在 痞客邦 留言(0) 人氣()