說明:在GridView的樣板裡放了LinkButton,並想根據點選LinkButton後紀錄的Status來繫結LinkButton最新的狀態(Enable/Disable)。
例:
Process_No Process_Name Check-in Check-out
1 test LinkButton1 LinkButton2
若Process Check-in後,則LinkButton1 Disable LinkButton2 Enable
作法:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnCheckIn = (Button)e.Row.FindControl("btnCheckIn");
Button btnCheckOut = (Button)e.Row.FindControl("btnCheckOut");
btnCheckIn.Enabled = false;
btnCheckOut.Enabled = false;
//取得繫結於GridView中各row的Check_Status值
string strCheckStatus = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Check_Status"));
//Initial
if (strCheckStatus == "0")
{
btnCheckIn.Enabled = true;
}
//Check in
else if (strCheckStatus == "1")
{
btnCheckOut.Enabled = true;
}
}
}
參考來源:
http://stackoverflow.com/questions/17207271/enable-and-disable-link-button-on-gridview
沒有留言:
張貼留言