DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
else set @SQL=′select top ′+str(@pageSize) +′ * from ( select top ′+str(@recordCount - @pageSize * @pageIndex)+′ productID,productName, unitPrice from products order by productID desc) TempTable order by productID asc′
private uint recordCount; //总记录数
private DataSet GetPageData(uint pageSize, uint pageIndex)
{
string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand command = new SqlCommand("GetCustomDataPage",conn); //第一个参数为存储过程名
command.CommandType = CommandType.StoredProcedure; //声明命令类型为存储过程
command.Parameters.Add("@pageSize",SqlDbType.Int);
command.Parameters["@pageSize"].Value = pageSize;
command.Parameters.Add("@pageIndex",SqlDbType.Int);
command.Parameters["@pageIndex"].Value = pageIndex;
command.Parameters.Add("@pageCount",SqlDbType.Int);
command.Parameters["@pageCount"].Value = pageCount;
command.Parameters["@pageCount"].Direction = ParameterDirection.Output; //存储过程中的输出参数
command.Parameters.Add("@recordCount",SqlDbType.Int);
command.Parameters["@recordCount"].Value = recordCount;
command.Parameters["@recordCount"].Direction = ParameterDirection.Output; //存储过程中的输出参数
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);
//获得输出参数值
pageCount = Convert.ToUInt32(command.Parameters["@pageCount"].Value);
recordCount = Convert.ToUInt32(command.Parameters["@recordCount"].Value);
conn.Close();
return ds;
}
//绑定数据到DataGrid中
private void BindDataGrid()
{
DataSet ds = GetPageData((uint)dgProduct.PageSize,(uint)dgProduct.CurrentPageIndex);
dgProduct.VirtualItemCount = (int)recordCount;
dgProduct.DataSource = ds;
dgProduct.DataBind();
}
//页面加载时就绑定DataGrid
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindDataGrid();
}
}
//用户翻页时事件处理
private void dgProduct_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgProduct.CurrentPageIndex = e.NewPageIndex;
BindDataGrid();
}
//用户单击编辑按纽时事件处理
private void dgProduct_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgProduct.EditItemIndex = e.Item.ItemIndex;
BindDataGrid();
}
//用户单击取消按纽时事件处理
private void dgProduct_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgProduct.EditItemIndex = -1;
BindDataGrid();
}
//用户单击更新按纽时事件处理
private void dgProduct_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
//string strSQL = "update from products set productName=@productName, set unitPrice=@unitPrice where productID=@productID";
string strSQL = "update products set productName=@productName where productID=@productID";
SqlCommand command = new SqlCommand(strSQL,conn);
command.Parameters.Add("@productName",SqlDbType.NVarChar,40);
command.Parameters["@productName"].Value = ((TextBox)(e.Item.Cells[1].Controls[0])).Text.Trim();
//command.Parameters.Add("@unitPrice",SqlDbType.Int);
//command.Parameters["@unitPrice"].Value = Convert.ToInt32(((TextBox)(e.Item.Cells[2].Controls[0])).Text.Trim());
command.Parameters.Add("@productID",SqlDbType.Int);
command.Parameters["@productID"].Value = dgProduct.DataKeys[e.Item.ItemIndex];
command.ExecuteNonQuery();
conn.Close();
dgProduct.EditItemIndex = -1;
BindDataGrid();
}
//用户单击删除按纽时事件处理
private void dgProduct_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand command = new SqlCommand("DeleteProduct",conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@productID",SqlDbType.Int);
command.Parameters["@productID"].Value = dgProduct.DataKeys[e.Item.ItemIndex];
command.ExecuteNonQuery();
BindDataGrid();
}
//实现删除确认及颜色交替显示功能
private void dgProduct_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
Button btnDelete = (Button)(e.Item.Cells[4].Controls[0]);
btnDelete.Attributes.Add("onClick","JavaScript:return confirm(’确定删除?’)");
e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor=’#FFCC66’");
e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor=’#ffffff’");
}
}
转自: http://blog.csdn.net/JavaProgramers/archive/2006/07/18/935698.aspx ,,今天一不小心转了几篇文章!但我还是坚持自己写的!
DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除相关推荐
- Henry手记—Web Form中的Datagrid的自定义分页 (转)
Henry手记-Web Form中的Datagrid的自定义分页 (转)[@more@] Henry手记-web Form中的Datagrid的自定义分页XML:namespace prefix = ...
- Henry手记—Web Form中的Datagrid的自定义分页
Henry手记-Web Form中的Datagrid的自定义分页 韩睿 ( 05/31/2003) ASP.NET带给我们很多惊喜,强大的Web Form控件自然是其中的重要部分. ...
- Web Form中的Datagrid的自定义分页
ASP.NET带给我们很多惊喜,强大的Web Form控件自然是其中的重要部分.这其中,最受关注的当然是Datagrid.在ASP中用HTML标记语法来输出数据的方法在Datagrid数据绑定面前显得 ...
- Henry手记—Web Form中的Datagrid的自定义分页(转)
原文:http://blog.csdn.net/Latitude/archive/2003/06/02/17227.aspx 韩睿 ( 05/31/2003) ASP.NET带给我们很多惊喜,强大的 ...
- JS-隔行换色+鼠标移上去变色
<style>ul{list-style: none;} </style> <body><ul><li>111</li>< ...
- 用jQuery一句话实现鼠标移上变色
按钮移上变色效果 <style> .round-corner-btn { -moz-border-radius:4px; -webkit-b ...
- html鼠标移上去变色放大,CSS3 鼠标滑过图片突出放大效果 | 腾讯云
今天给大家分享一款简单实用的CSS3鼠标滑过图片放大特效,我们可以将它应用在相册中,或者是轮播展示的图片中,这样可以将鼠标移到图片上进行快速预览图片.同时你也可以在此基础上扩展它,比如给图片加投影和边 ...
- ASP.NET中利用DataGrid的自定义分页功能和存储过程结合实现高效分页
关键字:DataGrid.存储过程.分页 出自: http://blog.csdn.net/yzx110/archive/2004/08/18/78525.aspx 摘要:在最进的一个项目中因为一个管 ...
- ASP.NET中 DataGrid简单自定义分页
先在pageload中添加事件 private void Page_Load(object sender, System.EventArgs e) { ...
最新文章
- 核酸序列特征信息分析
- 普通话计算机考试相关信息,普通话考试常见问题有哪些
- 进度条(python 实现)
- oracle 提取首字母,oracle 取字段文字拼音首字母
- 清华提出LogME,无需微调就能衡量预训练模型的下游任务表现!
- java爬取网页并保存_第九讲:Python爬取网页图片并保存到本地
- OpenCV之图像的遮挡与切分、合并(笔记06)
- mac 连接hbase的图形化界面_Mac 视觉史(二):90 年代失败 Mac 操作系统大赏
- golang 函数一 (定义、参数、返回值)
- HMM隐马尔可夫模型(HMM)攻略
- C#设计模式---迭代器模式(Iterator Pattern)
- Atitit zip解压文件 java use apache ant.jar C:\0wkspc\hislog\src\main\java\com\attilax\compress\ZipUt
- 微软ime日文输入法怎么设置切换过来就是输入假名的状态
- 数字电视业务PSI-SI学习系列
- 暑期参加CSDN编程竞赛的些许心得体会
- FastReport for Delphi2010 中文菜单显示不全或者乱码解决方法
- 英文歌曲:A place nearby (天堂若比邻)
- 【用户画像】Redis的常用五大数据类型和配置文件介绍
- 47 lvs-nat/dr
- TCP标志位详解(TCP Flag)