1

谁能帮我吗!当用户单击按钮时,我在 gridview 中向用户显示角色和资格记录,在 gridview 中,我为每一行生成了“删除”按钮。当用户单击删除时,我想将角色和资格单元格值传递给消息框或弹出窗口。(我正在使用 visualstudio 2010 和 Dotnet 3.5)

我的 C# 代码:

protected void OnRowDelete_grid_admin(object sender, GridViewDeleteEventArgs e)
{
    TableCell cell = grid_admin.Rows[e.RowIndex].Cells[0];
    string CellValue = grid_admin.SelectedRow.Cells[0].Text;
    string CellValue2 = grid_admin.SelectedRow.Cells[1].Text;
    Response.Write("<script>alert('Are you sure to delete' + CellValue + Cellvalue2)</script>");                    
}
4

5 回答 5

1
   TableCell cell = grid_admin.Rows[e.RowIndex].Cells[0];
   string CellValue= cell.Text;

   TableCell cell1 = grid_admin.Rows[e.RowIndex].Cells[1];
   string CellValue2 = cell1.text; 

Response.Write("<script>alert('Are you sure to delete' + CellValue + Cellvalue2)</script>");
于 2013-10-08T09:55:11.290 回答
0

尝试这个

string CellValue=grid_admin.Rows[e.RowIndex].Cells[0].Value;
于 2013-10-08T05:49:47.873 回答
0

我认为你的删除控制是一个LinkButton?那么这可能有效:

LinkButton lb = (LinkButton)e.CommandSource;
GridViewRow gvr = (GridViewRow)lb.NamingContainer;
Label lbl1 = gvr.FindControl("NAMEOFLABEL1") as Label;
Label lbl2 = gvr.FindControl("NAMEOFLABEL2") as Label;
Response.Write("<script>alert('Are you sure to delete' + lbl1.Text + lbl2.Text)</script>");
于 2013-10-08T05:51:17.757 回答
0

关于行删除的 MSDN 链接

String value = gridViewID.Rows[e.RowIndex].Cells[2].Text;
于 2013-10-08T05:53:44.440 回答
0

这是我执行的代码!根据建议的答案,我有这个代码

protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
 {
 ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('Are You sure to Delete EmpId:" + grid_admin.Rows[e.RowIndex].Cells[2].Text + " from the Role" + grid_admin.Rows[e.RowIndex].Cells[1].Text +"')", true); 
   }
于 2013-10-08T09:34:39.583 回答