1

我想要做的是当用户单击删除按钮时,我想突出显示整行并在删除之前要求确认,以下是我的代码和 iw ant 执行两个步骤:1)突出显示整行 2)要求确认。

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

1 回答 1

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;
}
于 2011-02-04T03:18:17.227 回答