2011-05-05 67 views
0

我有保存按鈕作爲網格的EditItemTemplate的一部分。點擊該按鈕我想禁用該按鈕以獲得單擊禁用效果。在gridview中禁用保存按鈕

  1. 我曾嘗試使用JavaScript,在這種情況下沒有執行服務器端代碼。
  2. 添加的屬性的按鈕,即使這不利於
  3. 試圖通過增加UseSubmitBehavior="false"財產太

什麼是其他可能的解決方案來實現這一目標?

+0

保護無效gvw_RowDataBound(對象發件人,GridViewRowEventArgs E) { 如果((e.Row .RowState&DataControlRowState.Edit)> 0) { Button btn =(Button)e.Row.Cells [6] .FindControl(「btnSave」); btn.Attributes.Add(「onclick」,「this.disabled = true;」); } } } – user739298 2011-05-05 06:32:32

+0

這是您的解決方案的代碼或必需的答案 – Dotnet 2011-05-05 06:47:45

回答

0

(可以通過在一個問題編輯轉換爲一個社區維基答案回答見Question with no answers, but issue solved in the comments (or extended in chat)

的OP寫道:

這裏是解決方案:

  1. aspx頁面設置按鈕UseSubmitBehavior="false"

  2. .c秒Page,在RowDataBound事件寫入以下代碼:

///Grid row event RowDataBound 
protected void gvr_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     if ((e.Row.RowState & DataControlRowState.Edit) > 0) 
     { 
      ///Creating the Save button object 
      Button btn = (Button)e.Row.Cells[6].FindControl("btnSave"); 

      ///Add the attribute to disblae the button 
      btn.Attributes.Add("onclick", "this.disabled=true;"); 
     } 
    } 
}