GridView中刪除一列時,彈出詢問對話框,及選中一行後使該行變背景色。
GridView中刪除一列時,彈出詢問對話框,如下圖所示:
後台代碼:
protected void GridUsers_RowDataBound(object sender, GridViewRowEventArgs e) { if(e.Row.Cells[0].HasControls()) { LinkButton BtnDelete = (LinkButton)e.Row.Cells[0].Controls[2]; LinkButton BtnUpdate = (LinkButton)e.Row.Cells[0].Controls[0]; if(BtnDelete.Text.Equals("刪除")) { BtnDelete.Attributes.Add("onclick","javascript:return confirm('"+string.Format("您確認要刪除管理員{0}嗎?",DataBinder.Eval(e.Row.DataItem,"UserName"))+"')"); } if (BtnUpdate.Text.Equals("更新")) { BtnUpdate.Attributes.Add("onclick", "javascript:return confirm('" + string.Format("您確認要更新管理員{0}嗎?", DataBinder.Eval(e.Row.DataItem, "UserName")) + "')"); } } if(e.Row.RowType==DataControlRowType.DataRow) { CheckBox CheckSingle = e.Row.Cells[4].FindControl("CheckSingle") as CheckBox; CheckSingle.Attributes.Add("onclick","javascript:changecolor(this,'"+e.Row.ClientID+"')"); } //對應客戶端的JavaScript腳本: /* function changecolor(cbo,o) { var theBox=cbo; var tr=document.getElementById(o); if(theBox.checked) { tr.style.backgroundColor="Red"; } else { tr.style.backgroundColor="#CCCCCC"; } } */ }
最後更新:2017-04-02 04:00:23