asp.net GridView 删除时弹出确认…
来源:互联网 发布:天国王朝 演员 知乎 编辑:程序博客网 时间:2024/05/01 13:56
GridView 删除时弹出确认对话框(包括内容提示)
效果图:
html代码
复制代码 代码如下:
- <table align="center" bgcolor="#c0de98"border="0" cellpadding="0" cellspacing="1"width="99%">
- <tr>
- <thcolspan="2">
- GridView演示</th>
- </tr>
- <tr>
- <td colspan="2" style="width: 100%;">
- <asp:GridView ID="GridView" runat="server"Width="100%" AllowPaging="True"OnPageIndexChanging="GridView_PageIndexChanging" PageSize="12"OnRowDeleting="GridView_RowDeleting"OnRowDataBound="GridView_RowDataBound">
- <Columns>
- <asp:BoundField DataField="UserID"HeaderText="UserID" ReadOnly="True"/>
- <asp:BoundField DataField="C_Name"HeaderText="中文名字" ReadOnly="True"/>
- <asp:BoundField DataField="E_Name"HeaderText="英文名字" ReadOnly="True"/>
- <asp:BoundField DataField="QQ" HeaderText="QQ帐号"/>
- <asp:CommandField HeaderText="删除"ShowDeleteButton="True" />
- </Columns>
- <RowStyle HorizontalAlign="Center"/>
- <PagerStyle HorizontalAlign="Right"/>
- </asp:GridView>
- </td>
- </tr>
- </table>
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;
- usingSystem.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class Demo11 :System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgse)
- {
- 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_Userwhere
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 +"\"吗?')");
- }
- }
- }
- }
0 0
- asp.net GridView 删除时弹出确认…
- ASP.NET GridView 激发…
- asp.net GridView 删除时弹出确认对话框(包括内容提示)
- ASP.NET 2.0 GridView的RowCommand…
- ASP.NET 中 GridView&nb…
- asp.net gridview添加删除确认对话框
- GridView实现删除时弹出确认对话框
- GridView实现删除时弹出确认对话框
- GridView删除时弹出确认对话框
- GridView实现删除时弹出确认对话框
- asp.net gridview中行的控制..例如…
- ASP.NET 控件Gridview中e.Row…
- ASP.NET Request.Query…
- ASP.NET DropDownList&…
- ASP.NET中为GridView添加删除确认提示框
- 有确认删除的gridview(vs2005 asp.net)
- [推荐]ASP.NET视频教程 主…
- ASP.NET 出现错误 &nbsp…
- 【转载】Repeater隔行变色,两个方…
- 获取ul下所有li
- GridView绑定ArraryList
- GridView 全选问题
- GridView控件与CheckBox结合,实现…
- asp.net GridView 删除时弹出确认…
- 页面使用Ajax控件,后台不能调用前…
- 页面音乐和视频播发器代码
- jQuery插件---获取URL参数
- 查询并删除重复记录的SQL语句
- JS禁用鼠标左键和自动关闭弹出窗口
- SQL server中如何只备份一张数据库表的数据
- java.lang.RuntimeException: Unable to start activity ComponentInfo解决方案
- JavaScript基础学习零碎知识记录