1.html
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataList_DeleteUpdate1.aspx.cs"
Inherits="DataList_DataList_DeleteUpdate1" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>DataList编辑、更新、取消、删除、分页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:DataList ID="DataList1" runat="server" Font-Size="12px" Width="100%" DataKeyField="ProductID"
OnCancelCommand="DataList1_CancelCommand" OnDeleteCommand="DataList1_DeleteCommand"
OnEditCommand="DataList1_EditCommand" OnUpdateCommand="DataList1_UpdateCommand">
<HeaderTemplate>
<td>
au_id</td>
<td>
au_lname</td>
<td>
au_fname</td>
<td>
phone</td>
<td>
address</td>
<td>
编辑</td>
<td>
删除</td>
</HeaderTemplate>
<ItemTemplate>
<td>
<asp:Label ID="Lbl_au_id" Text='<%#Eval("au_id")%>' runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Lbl_au_lname" Text='<%#Eval("au_lname")%>' runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Lbl_au_fname" Text='<%#Eval("au_fname")%>' runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Lbl_phone" Text='<%#Eval("phone")%>' runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Lbl_address" Text='<%#Eval("address")%>' runat="server"></asp:Label>
</td>
<td>
<asp:LinkButton ID="LinkButton1" Text="编辑" CommandName="Edit" runat="server"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="LinkButton3" Text="删除" CommandName="Delete" runat="server"></asp:LinkButton>
</td>
</ItemTemplate>
<EditItemTemplate>
<td>
<asp:Label ID="Lbl_au_id" Text='<%#Eval("au_id")%>' runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="Txt_au_lname" Text='<%#Eval("au_lname")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Txt_au_fname" Text='<%#Eval("au_fname")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Txt_phone" Text='<%#Eval("phone")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Txt_address" Text='<%#Eval("address")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:LinkButton ID="LinkButton1" Text="更新" CommandName="Update" runat="server"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" Text="取消" CommandName="Cancel" runat="server"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="LinkButton3" Text="删除" CommandName="Delete" runat="server"></asp:LinkButton>
</td>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
</td>
</tr>
<tr>
<td align="center">
<webdiyer:AspNetPager ID="pager1" runat="server" Font-Size="12px" ShowCustomInfoSection="Left"
OnPageChanged="ChangePage" ShowInputBox="Always" CustomInfoSectionWidth="80%"
SubmitButtonText="go">
</webdiyer:AspNetPager>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
2.csInherits="DataList_DataList_DeleteUpdate1" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>DataList编辑、更新、取消、删除、分页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:DataList ID="DataList1" runat="server" Font-Size="12px" Width="100%" DataKeyField="ProductID"
OnCancelCommand="DataList1_CancelCommand" OnDeleteCommand="DataList1_DeleteCommand"
OnEditCommand="DataList1_EditCommand" OnUpdateCommand="DataList1_UpdateCommand">
<HeaderTemplate>
<td>
au_id</td>
<td>
au_lname</td>
<td>
au_fname</td>
<td>
phone</td>
<td>
address</td>
<td>
编辑</td>
<td>
删除</td>
</HeaderTemplate>
<ItemTemplate>
<td>
<asp:Label ID="Lbl_au_id" Text='<%#Eval("au_id")%>' runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Lbl_au_lname" Text='<%#Eval("au_lname")%>' runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Lbl_au_fname" Text='<%#Eval("au_fname")%>' runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Lbl_phone" Text='<%#Eval("phone")%>' runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Lbl_address" Text='<%#Eval("address")%>' runat="server"></asp:Label>
</td>
<td>
<asp:LinkButton ID="LinkButton1" Text="编辑" CommandName="Edit" runat="server"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="LinkButton3" Text="删除" CommandName="Delete" runat="server"></asp:LinkButton>
</td>
</ItemTemplate>
<EditItemTemplate>
<td>
<asp:Label ID="Lbl_au_id" Text='<%#Eval("au_id")%>' runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="Txt_au_lname" Text='<%#Eval("au_lname")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Txt_au_fname" Text='<%#Eval("au_fname")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Txt_phone" Text='<%#Eval("phone")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Txt_address" Text='<%#Eval("address")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:LinkButton ID="LinkButton1" Text="更新" CommandName="Update" runat="server"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" Text="取消" CommandName="Cancel" runat="server"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="LinkButton3" Text="删除" CommandName="Delete" runat="server"></asp:LinkButton>
</td>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
</td>
</tr>
<tr>
<td align="center">
<webdiyer:AspNetPager ID="pager1" runat="server" Font-Size="12px" ShowCustomInfoSection="Left"
OnPageChanged="ChangePage" ShowInputBox="Always" CustomInfoSectionWidth="80%"
SubmitButtonText="go">
</webdiyer:AspNetPager>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
using System;
using System.Data;
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;
using Wuqi.Webdiyer;
public partial class DataList_DataList_DeleteUpdate1 : System.Web.UI.Page
{
public string tblName = "authors";//表名
public string fldName = "au_id";//主键字段名
public int IsReCount = 1;//是否
public int OrderType = 0;//排序 0升,非0降
public string strWhere = "";//条件
Practice.DAL.authors authorsbll = new Practice.DAL.authors();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
pager1.CurrentPageIndex = 1;//页数
pager1.PageSize = 5;//每页多少条
pager1.RecordCount = Convert.ToInt32(GetDataSet().Tables[1].Rows[0][0].ToString());//共多少条
DataBindGridView();
}
}
//返回dataSet
private DataSet GetDataSet()
{
DataSet ds = authorsbll.Minutepage(tblName, fldName, pager1.PageSize, pager1.CurrentPageIndex, IsReCount, OrderType, strWhere);
return ds;
}
//绑定GridView
private void DataBindGridView()
{
DataList1.DataSource = GetDataSet().Tables[0];
DataList1.DataKeyField = fldName;
DataList1.DataBind();
//显示记录信息
pager1.CustomInfoText = "记录总数:<b>" + pager1.RecordCount.ToString() + "</b>";
pager1.CustomInfoText += " 总页数:<b>" + pager1.PageCount.ToString() + "</b>";
pager1.CustomInfoText += " 当前页:<font color=\"red\"><b>" + pager1.CurrentPageIndex.ToString() + "</b></font>";
}
//DataList编辑
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = e.Item.ItemIndex;
DataBindGridView();
}
//DataList取消
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = -1;
DataBindGridView();
}
//DataList更新
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
string au_id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
string au_lname = ((TextBox)e.Item.FindControl("Txt_au_lname")).Text.Trim();
Response.Write("更新时:<br/>au_id: " + au_id + "<br/>au_lname: " + au_lname);
DataList1.EditItemIndex = -1;
DataBindGridView();
}
//DataList删除
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
{
string au_id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
string au_lname = ((Label)e.Item.FindControl("Lbl_au_lname")).Text.Trim();
Response.Write("删除时:<br/>au_id: " + au_id + "<br/>au_lname: " + au_lname);
DataBindGridView();
}
//分页
protected void ChangePage(object src, PageChangedEventArgs e)
{
pager1.CurrentPageIndex = e.NewPageIndex;
DataBindGridView();
}
}
3.Minutepage函数using System.Data;
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;
using Wuqi.Webdiyer;
public partial class DataList_DataList_DeleteUpdate1 : System.Web.UI.Page
{
public string tblName = "authors";//表名
public string fldName = "au_id";//主键字段名
public int IsReCount = 1;//是否
public int OrderType = 0;//排序 0升,非0降
public string strWhere = "";//条件
Practice.DAL.authors authorsbll = new Practice.DAL.authors();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
pager1.CurrentPageIndex = 1;//页数
pager1.PageSize = 5;//每页多少条
pager1.RecordCount = Convert.ToInt32(GetDataSet().Tables[1].Rows[0][0].ToString());//共多少条
DataBindGridView();
}
}
//返回dataSet
private DataSet GetDataSet()
{
DataSet ds = authorsbll.Minutepage(tblName, fldName, pager1.PageSize, pager1.CurrentPageIndex, IsReCount, OrderType, strWhere);
return ds;
}
//绑定GridView
private void DataBindGridView()
{
DataList1.DataSource = GetDataSet().Tables[0];
DataList1.DataKeyField = fldName;
DataList1.DataBind();
//显示记录信息
pager1.CustomInfoText = "记录总数:<b>" + pager1.RecordCount.ToString() + "</b>";
pager1.CustomInfoText += " 总页数:<b>" + pager1.PageCount.ToString() + "</b>";
pager1.CustomInfoText += " 当前页:<font color=\"red\"><b>" + pager1.CurrentPageIndex.ToString() + "</b></font>";
}
//DataList编辑
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = e.Item.ItemIndex;
DataBindGridView();
}
//DataList取消
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = -1;
DataBindGridView();
}
//DataList更新
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
string au_id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
string au_lname = ((TextBox)e.Item.FindControl("Txt_au_lname")).Text.Trim();
Response.Write("更新时:<br/>au_id: " + au_id + "<br/>au_lname: " + au_lname);
DataList1.EditItemIndex = -1;
DataBindGridView();
}
//DataList删除
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
{
string au_id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
string au_lname = ((Label)e.Item.FindControl("Lbl_au_lname")).Text.Trim();
Response.Write("删除时:<br/>au_id: " + au_id + "<br/>au_lname: " + au_lname);
DataBindGridView();
}
//分页
protected void ChangePage(object src, PageChangedEventArgs e)
{
pager1.CurrentPageIndex = e.NewPageIndex;
DataBindGridView();
}
}
/// <summary>
/// 功 能:分页
/// 作 者:PUKE
/// 完成时间:2007-05-28
/// 版 权:pukesys@tom.com
/// </summary>
/// <param name="tblName">表名</param>
/// <param name="fldName">主键字段名</param>
/// <param name="PageSize">页尺寸</param>
/// <param name="PageIndex">页码</param>
/// <param name="IsReCount">返回记录总数, 非 0 值则返回</param>
/// <param name="OrderType">设置排序类型, 非 0 值则降序</param>
/// <param name="strWhere">查询条件 (注意: 不要加 where)</param>
/// <returns>ds</returns>
public DataSet Minutepage(string tblName,string fldName,int PageSize,int PageIndex,int IsReCount,int OrderType,string strWhere)
{
SqlParameter[] parameters = {
new SqlParameter("@tblName", SqlDbType.VarChar,255),
new SqlParameter("@fldName",SqlDbType.VarChar,255),
new SqlParameter("@PageSize", SqlDbType.Int),
new SqlParameter("@PageIndex", SqlDbType.Int),
new SqlParameter("@IsReCount",SqlDbType.Bit),
new SqlParameter("@OrderType",SqlDbType.Bit),
new SqlParameter("@strWhere",SqlDbType.VarChar,1000)
};
parameters[0].Value = tblName;
parameters[1].Value = fldName;
parameters[2].Value = PageSize;
parameters[3].Value = PageIndex;
parameters[4].Value = IsReCount;
parameters[5].Value = OrderType;
parameters[6].Value = strWhere;
return DbHelperSQL.RunProcedure("PR_MinutePage", parameters, "ds");
}
/// 功 能:分页
/// 作 者:PUKE
/// 完成时间:2007-05-28
/// 版 权:pukesys@tom.com
/// </summary>
/// <param name="tblName">表名</param>
/// <param name="fldName">主键字段名</param>
/// <param name="PageSize">页尺寸</param>
/// <param name="PageIndex">页码</param>
/// <param name="IsReCount">返回记录总数, 非 0 值则返回</param>
/// <param name="OrderType">设置排序类型, 非 0 值则降序</param>
/// <param name="strWhere">查询条件 (注意: 不要加 where)</param>
/// <returns>ds</returns>
public DataSet Minutepage(string tblName,string fldName,int PageSize,int PageIndex,int IsReCount,int OrderType,string strWhere)
{
SqlParameter[] parameters = {
new SqlParameter("@tblName", SqlDbType.VarChar,255),
new SqlParameter("@fldName",SqlDbType.VarChar,255),
new SqlParameter("@PageSize", SqlDbType.Int),
new SqlParameter("@PageIndex", SqlDbType.Int),
new SqlParameter("@IsReCount",SqlDbType.Bit),
new SqlParameter("@OrderType",SqlDbType.Bit),
new SqlParameter("@strWhere",SqlDbType.VarChar,1000)
};
parameters[0].Value = tblName;
parameters[1].Value = fldName;
parameters[2].Value = PageSize;
parameters[3].Value = PageIndex;
parameters[4].Value = IsReCount;
parameters[5].Value = OrderType;
parameters[6].Value = strWhere;
return DbHelperSQL.RunProcedure("PR_MinutePage", parameters, "ds");
}