【问题标题】:Highlight GridView Rows only when Delete button is clicked仅在单击删除按钮时突出显示 GridView 行
【发布时间】:2011-02-04 02:31:10
【问题描述】:

我想要做的是当用户单击删除按钮时,我想突出显示整行并在删除之前要求确认,以下是我的代码和 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")));
    }
}

【问题讨论】:

    标签: asp.net gridview aspxgridview


    【解决方案1】:
    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;
    }
    

    【讨论】:

    • 一件小事我发现我有交替行` `那么我怎样才能恢复相同的交替行?
    猜你喜欢
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 2017-11-18
    • 2013-08-08
    • 1970-01-01
    • 2020-11-12
    • 2021-05-12
    相关资源
    最近更新 更多