html代码
<table align="center" bgcolor="#c0de98" border="0" cellpadding="0" cellspacing="1" width="99%">
<tr>
<th colspan="2">
GridView演示</th>
</tr>
<tr>
<td colspan="2" style="width: 100%;" >
<asp:GridView ID="GridView" runat="server" Width="100%" AutoGenerateColumns="False" 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>
<tr>
<th colspan="2">
GridView演示</th>
</tr>
<tr>
<td colspan="2" style="width: 100%;" >
<asp:GridView ID="GridView" runat="server" Width="100%" AutoGenerateColumns="False" 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;
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 + "\"吗?')");
}
}
}
}
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 + "\"吗?')");
}
}
}
}
发表评论
-
GridView 72般绝技
2011-11-19 10:05 809GridView无代码分页排 ... -
ASP.NET 替换字符 防SQL注入
2011-11-19 10:06 852/// <summary> /// 处理字符 ... -
Server.HTMLEncode用法
2011-11-19 10:06 1218Server.HTMLEncode HTML ... -
web.config数据库连接
2011-11-19 10:06 1620Web.Config 配置文件里连接SQL数据库,主要有 ... -
ASP.NET日期处理函数
2011-11-19 10:06 13051、DateTime 数字型 System.DateTi ... -
ASP.NET获取不到js写的cookie解决方法
2011-11-18 11:15 1580今晚使用javascript设置一个来路的cookie, ... -
Net 4.0的UrlRouting实现友好的URL
2011-11-18 11:12 732在.Net 4.0之前我们为了做出搜索引擎友好的,对用户 ... -
ASP.NET中JSON的序列化和反序列化
2011-11-18 11:09 959导读:JSON是专门为浏览器中的网页上运行的JavaSc ... -
ASP.NET Session丢失原因和应对策略
2011-11-18 11:07 813正常操作情况下会有A ... -
TextBox控件
2010-12-20 19:15 750SingleLine—显示单行输入栏. MultiLi ... -
asp.net消息提示框代码
2010-12-20 18:07 1304/// <summary> /// ... -
ASP.NET Request.QueryString[""] 的用法
2010-12-20 01:05 1629Request.QueryString是用来获取参 ... -
检测远程URL是否存在的三种方法
2010-06-07 12:35 766private void Page_Load(object s ... -
ASP.NET4.0 新功能之 ViewStateMode 属性
2010-06-07 12:34 1460ASP.NET4.0 提供了一个叫做 ViewStateMod ... -
ASP.NET 中得到网站绝对路径的几种方法
2010-06-07 12:32 2276在编写 ASP.NET 应用程序的时候,有时为了更好地进行控制 ... -
.net生成静态页面
2010-05-28 14:45 1072模板页moban.htm <html> < ... -
在服务器端使用StringBuilder 对Web控件进行验证
2010-05-28 14:40 841导入命名空间using System.Text; pri ... -
日历控件的事件
2010-05-13 17:07 714 DayRender:当日期被显示时触发该事件。 Sele ... -
判断字符串是否为数字的方法
2010-05-01 12:42 10921﹑使用Try...Catch pri ... -
连接SQL数据库字符串
2010-04-30 22:59 570Data Source=(local);Initial Cat ...
相关推荐
GridView实现删除时弹出确认对话框
GridView 删除时弹出确认对话框(包括内容提示)
为GRIDVIEW“删除”列添加确认对话框 确认对话框
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...
1.无代码分页排序 2.选中,编辑,取消,删除 ...8.GridView实现删除时弹出确认对话框 9.GridView实现自动编号 10.GridView实现自定义时间货币等字符串格式 11.GridView实现用“...”代替超长字符串
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...
GridView实现删除时弹出确认对话框 GridView实现自动编号 GridView实现自定义时间货币等字符串格式 GridView实现用“...”代替超长字符串 GridView一般换行与强制换行 GridView显示隐藏某一列 GridView弹出新页面/弹...