如何将网格视图的单元格值传递到消息框
本文关键字:值传 消息 单元格 网格 视图 | 更新日期: 2023-09-27 18:34:25
谁能帮我!当用户单击按钮时,我在网格视图中向用户显示角色和资格记录,在网格视图中,我为每一行生成了"删除"按钮。当用户单击"删除"时,我希望将角色和资格单元格值传递到消息框或弹出窗口。(我使用的是 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>");
}
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>");
试试这个
string CellValue=grid_admin.Rows[e.RowIndex].Cells[0].Value;
我认为您的删除控制是一个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>");
MSDN 行删除链接
String value = gridViewID.Rows[e.RowIndex].Cells[2].Text;
这是我执行的代码!根据建议的答案,我有此代码
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);
}