DataList编辑、更新、取消、删除、分页,分页用的是AspNetPager.dll4.3控 件,功能挺强大的,自己可以到网上下个

1.aspx

程序代码
<%@ 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 编辑、更新、取消、删除、分页 - Flywe の Blog</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.cs

程序代码
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 函数

程序代码
/** <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");
        }

转载于:https://www.cnblogs.com/superlee/archive/2010/01/06/1640151.html

DataList编辑、更新、取消、删除、分页(分页控件 AspNetPager.dll)相关推荐

  1. GridView的编辑,更新,取消,删除等功能演示

    GridView的编辑,更新,取消,删除等功能演示 这是一个GridView应用的视频,内容很透彻的讲解了GridView的很多实用的技巧. 下载地址:http://download.cnblogs. ...

  2. ASP.NET2.0 分页控件 PagerPro.dll (1.1.0 最新)

    快来瞧,快来看了啊,新出炉的ASP.NET分页控件,热乎啦! 最新的ASP.NET2.0分页控件,经过对样式的处理,现有None和Standard两种样式,可以自定义是否显示Page Count 和 ...

  3. 使用存储过程,分页用户控件,jQuery进行Ajax分页!

    效果图:http://www.ukei.cn/ob1.html 代码这里下载/Files/genson/AjaxPager.rar l准备工作: jQuery,到http://www.jquery.c ...

  4. 做VB的,经常注册和反注册OCX控件和DLL链

    做VB的,经常注册和反注册OCX控件和DLL链 但是,每次都要 "开始"--"运行" --"regsvr32 C:\********\******.o ...

  5. java jni ocx_Java调用ocx控件以及dll

    [ 通过Java调用OCX控件有几种方法,JNI.JACOB.Jawin等 1.JNI 最直接的方式,也是最麻烦的方式,需要自己完成所有的工作,不推荐. 2.Jawin 尝试了一下,效果不错,但相 通 ...

  6. Silverlight客户端分页 DataPager控件的使用

    首先拖入一个数据表格DataGrid控件,再拖入一个分页控件DataPager. 后台进行数据绑定的代码如下: PagedCollectionView pcv = new PagedCollectio ...

  7. asp.net中分页控件AspNetPager美化样式

    在asp.net开发中数据列表分页是再常见不过的功能了,相信大家使用AspNetPager的也很多,使用CSS可以让样式更好看,如下图: 新建一个名为content.css文件,如下: /*分页控件* ...

  8. DevExpress的分页Tab控件XtraTabControl控件的使用

    场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...

  9. word 删除所有 ActiveX控件,重新启用word自动保存

    背景 最近在学习课程,会用到word记录一些错题,从网页复制到word里,发现会把在线考试的html网页的选择控件也给复制进来,纯文本粘贴又会缺少图片和格式等信息.重点是我在onedrive操作的,自 ...

最新文章

  1. 学python的心得体会-Python学习心得
  2. 用Latex写IEEE论文
  3. 交换机端口灯闪烁频率一样_思创易控cetron-新品S2024GE 24口全千兆非网管交换机即将上市!...
  4. 2018/Province_Java_A/2/星期一
  5. 蓝桥杯第八届省赛JAVA真题----Excel地址
  6. 线性降维:PCA、LDA、MDS
  7. centos + nodejs + egg2.x 开发微信分享功能
  8. python同时发送与接收_Python如何发送与接收大型数组
  9. 4.5亿!依图的AI芯片计划初步浮出水面
  10. 【E-DEEC】基于matlab增强的分布式能源有效集群(E-DEEC)【含Matlab源码 1566期】
  11. SEO项目管理,该问自己的几个问题?
  12. Ubuntu下批量修改文件名以及后缀名
  13. 树木根际微生物、树木-真菌互作研究方向博后和出站博后
  14. 东南大学研究生毕业论文LaTeX模板seuthesix的使用技巧【Mac版】
  15. 滴滴快车历史奖励政策:含工作日和周末的高峰奖励、翻倍奖励【历史政策】...
  16. 服务器如何防御网络攻击
  17. 2022登高架设理论题库及答案
  18. CDK【10元美团外卖通用红包】无门槛红包 2天内兑换 1天内可兑换5次 提示失败隔天兑换
  19. ESB即企业服务总线
  20. 28岁 计算机专硕,28岁我辞掉工作考研!

热门文章

  1. 开篇辞 vuejs 快讯 - 109 期
  2. PHP7 JIT 相关开源项目(JPHP)
  3. 利用zabbix-java-gateway监控jvm
  4. Node.js- sublime搭建node的编译环境
  5. Android全屏与透明状态栏
  6. CCpp.CallGraph
  7. nokia 基亚 wp 开发中心
  8. 移动热潮催火统一通信
  9. 优化调整Oracle 8i数据库
  10. CC2540开发板学习笔记(一)——LED点亮