DataGrid按鈕列的刪除按鈕

來源:互聯網
上載者:User

通常當我們單擊DataGrid按鈕列的刪除按鈕時,該行資料就會不經提示的直接刪除。
可否當我們單擊DataGrid按鈕列的刪除按鈕時,出現一個“是否確定刪除”的對話方塊,
之後按確定才真正刪除,按取消就取消刪除呢?
具體又該如何做?

//在項被資料繫結後激發的事件
private void dgBoard_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
         //判斷是否為項和交替項
 if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
 {
  //確認是否刪除
                  //Cells[你的刪除按鈕所在的index]
  LinkButton lnkDel=(LinkButton)e.Item.Cells[4].Controls[0];
                  //lnkDel是你刪除按鈕的id
  lnkDel.Attributes["onclick"]="return confirm('是否要刪除此項?');";

  //為滑鼠移動到的項和離開項時設定背景顏色
  e.Item.Attributes["onmouseover"]="c=this.style.backgroundColor;this.style.backgroundColor='#33ffff';";
    e.Item.Attributes["onmouseout"]="this.style.backgroundColor=c;";
   }
  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.