2011-02-04 82 views
1

我想要做的是當用戶單擊刪除按鈕時,我想突出顯示整行並在刪除之前要求確認,以下是我的代碼和iw ant執行兩步: 1)點亮整行 2)請求確認。只有點擊刪除按鈕時,纔會突出顯示GridView行

protected void gvOrg_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    Button btnDelete = (Button)e.Row.FindControl("btnDelete"); 
    if (btnDelete != null) 
    { 
      //btnDelete.Attributes.Add("onclick", e.Row.BackColor = System.Drawing.Color.Red); 
      btnDelete.Attributes.Add("onclick", String.Format(textForMessage, "Id: " + DataBinder.Eval(e.Row.DataItem, "Id"), "Name: " + DataBinder.Eval(e.Row.DataItem, "Name"))); 
    } 
} 

回答

4
protected void gvOrg_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    Button btnDelete = (Button)e.Row.FindControl("btnDelete"); 
    if (btnDelete != null) 
    { 
    btnDelete.Attributes.Add("onclick", 
     String.Format(@"return DeleteRow('{0}',{1});", 
     e.Row.ClientID,e.Row.RowIndex)); 
    } 
} 

//javascript 
function DeleteRow(rowId, rowIdx) 
{ 
    HighlightRow(rowId, "#FF0000"); 
    var result = confirm('Are you sure you want to delete this record?'); 
    if(!result) 
    HighlightRow(rowId, rowIdx % 2 ? "#DEEEE9" : "#FFFFFF"); 
    return result; 
} 

function HighlightRow(rowId, color) 
{ 
    var row = document.getElementById(rowId);  
    row.style.background = color; 
} 
+0

一個小件事我foud,我已交替行``所以如何恢復相同的交替行? – 2011-02-04 15:27:08

相關問題