Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > C#/.NET入门教程

asp.net GridView 删除时弹出确认对话框(包括内容提示)

来源:中文源码网    浏览:155 次    日期:2024-05-13 00:41:39
【下载文档:  asp.net GridView 删除时弹出确认对话框(包括内容提示).txt 】


asp.net GridView 删除时弹出确认对话框(包括内容提示)
效果图: html代码复制代码 代码如下:
GridView演示
C#代码复制代码 代码如下:using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Demo11 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { BindData(); } } public void BindData() { string strSql = "select UserID,C_Name,E_Name,QQ from Demo_User "; DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING, CommandType.Text, strSql, null).Tables[0]; GridView.DataSource = dt; GridView.DataKeyNames = new string[] { "UserID" };//主键 GridView.DataBind(); } protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView.PageIndex = e.NewPageIndex; BindData(); } protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { int UserID = (int)GridView.DataKeys[e.RowIndex].Value; string strSql = "Delete Demo_User where UserID=@UserID"; SqlParameter[] para = { new SqlParameter("@UserID", UserID), }; SqlHelper.ExecuteNonQuery(SqlHelper.CONN_STRING, CommandType.Text, strSql, para); BindData(); } protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) { ((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')"); } } } }

相关内容