1

私がしたいのは、ユーザーが [削除] ボタンをクリックしたときに、行全体を強調表示して、削除する前に確認を求めたいということです。以下は私のコードで、2 つの手順を実行したいです: 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 に答える