我想要做的是当用户点击删除按钮时我想要突出显示整行并在删除之前要求确认,以下是我的代码并且执行两个步骤: 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")));
}
}
答案 0 :(得分: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;
}