在iBATIS.NET 学习笔记(五)中的DataGrid中加入删除功能,删除客户信息。
修改Maps/Customers.xml,在statements标记中加入下面代码:

<delete id="DeleteCustomer"  parameterClass="string">
        delete from Customers where CustomerID=#value#
        </delete>

parameterClass是指传递进来的参数类型,这里的CustomerID 是varchar类型,所以采用string。
修改后的Test1.aspx

<%@ Page language="c#" Codebehind="Test1.aspx.cs" AutoEventWireup="false" Inherits="IbatisNet.Example.Test1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>Test1</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
            <asp:DataGrid id="dgList" runat="server" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
                BackColor="White" CellPadding="3" GridLines="Horizontal" AllowPaging="True" AutoGenerateColumns="False"
                DataKeyField="CustomerID">
                <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
                <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
                <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
                <ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
                <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
                <Columns>
                    <asp:BoundColumn DataField="CustomerID" HeaderText="CustomerID"></asp:BoundColumn>
                    <asp:BoundColumn DataField="CompanyName" HeaderText="CompanyName"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Address" HeaderText="Address"></asp:BoundColumn>
                    <asp:BoundColumn DataField="City" HeaderText="City"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Phone" HeaderText="Phone"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Fax" HeaderText="Fax"></asp:BoundColumn>
                    <asp:ButtonColumn Text="删除" CommandName="Delete"></asp:ButtonColumn>
                </Columns>
                <PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF"></PagerStyle>
            </asp:DataGrid>
        </form>
    </body>
</HTML>

修改后的Test1.aspx.cs

//***********************************************************
//*公司:
//*作者:YK
//*模块:Test1
//*功能:
//*创建日期:
//*修改日期:
//***********************************************************
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using IBatisNet.Common;
using IBatisNet.Common.Utilities;
using IBatisNet.DataMapper;
using IBatisNet.DataAccess;
namespace IbatisNet.Example
{
    /**//// <summary>
    /// Test1 的摘要说明。
    /// </summary>
    public class Test1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataGrid dgList;
    
        private void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面

            if(!Page.IsPostBack)
            {
            
                this.GetData();
            }
        }

        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /**//// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {    
            this.dgList.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgList_PageIndexChanged);
            this.dgList.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgList_DeleteCommand);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
        private void GetData()
        {
            this.dgList.DataSource =IbatisNet.Example.Mapper.Instance().QueryForList("GetAllCustomers",null);
            this.dgList.DataBind();
        }

        //翻页
        private void dgList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {
            this.dgList.CurrentPageIndex = e.NewPageIndex;
            this.GetData();
        }

        //删除
        private void dgList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) {
            string customerID = this.dgList.DataKeys[e.Item.ItemIndex].ToString();
            IbatisNet.Example.Mapper.Instance().Delete("DeleteCustomer",customerID);
            if(this.dgList.CurrentPageIndex>0&&this.dgList.Items.Count==1) {
                this.dgList.CurrentPageIndex = this.dgList.CurrentPageIndex -1; 
            }
            this.GetData();
        }
    }
}

转载于:https://www.cnblogs.com/yknb/archive/2006/07/19/454968.html

iBATIS.NET 学习笔记(八)相关推荐

  1. IBatis.Net学习笔记系列文章

    IBatis.Net是一个比较易用的ORM框架,使用起来较为方便.灵活. 在此记录我学习的过程,作为自己的一个总结. 1.IBatis.Net学习笔记一:开篇 2.IBatis.Net学习笔记二:下载 ...

  2. IBatis.Net学习笔记六--再谈查询

    在IBatis.Net学习笔记五--常用的查询方式 中我提到了一些IBatis.Net中的查询,特别是配置文件的写法. 后来通过大家的讨论,特别是Anders Cui 的提醒,又发现了其他的多表查询的 ...

  3. ReactJS学习笔记八:动画

    ReactJS学习笔记八:动画 分类: react学习笔记 javascript2015-07-06 20:27 321人阅读 评论(0) 收藏 举报 react动画 目录(?)[+] 这里只讨论Re ...

  4. 【opencv学习笔记八】创建TrackBar轨迹条

    createTrackbar这个函数我们以后会经常用到,它创建一个可以调整数值的轨迹条,并将轨迹条附加到指定的窗口上,使用起来很方便.首先大家要记住,它往往会和一个回调函数配合起来使用.先看下他的函数 ...

  5. python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑

    python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑 许多人在安装Python第三方库的时候, 经常会为一个问题困扰:到底应该下载什么格式的文件? 当我们点开下载页时, 一 ...

  6. ROS学习笔记八:创建ROS msg和srv

    ROS学习笔记八:创建ROS msg和srv 本节主要讲述了如何创建和建立ROS msg和srv,同时使用命令行工具rosmsg.rossrv和roscp. msg和srv简介 msg:描述ROS m ...

  7. Halcon 学习笔记八:颜色识别

    Halcon 学习笔记八:颜色识别 一.图像处理需要的知识 二.图像处理的预处理和分割过程 二.颜色识别的方法 三.例子一 四.例子二 五.例子三 一.图像处理需要的知识 1.图像处理基础(rgb(h ...

  8. ZooKeeper学习笔记(八):ZooKeeper集群写数据原理

    写数据原理 写流程直接请求发送给Leader节点 这里假设集群中有三个zookeeper服务端 ACK (Acknowledge character)即是确认字符,在数据通信中,接收站发给发送站的一种 ...

  9. MongoDB 学习笔记八 复制、分片、备份与恢复、监控

    MongoDB 学习笔记八 复制.分片.备份与恢复.监控 MongoDB复制(副本集) 什么是复制? MongoDB 复制原理 MongoDB 副本集设置 副本集添加成员 MongoDB 分片 分片 ...

最新文章

  1. linux temp文件夹在哪_Win10系统下使用linux命令的方法
  2. 实用手册|史上最全的Pycharm快捷键操作
  3. 【Linux】一步一步学Linux——xeyes命令(228)
  4. python写入数据库_Python pymysql写入数据库报错
  5. Sql Server之旅——第八站 看公司这些DBA们设计的这些复合索引
  6. 工作339:pc父组件通过props传值给子组件,如何避免子组件改变props的属性值报错问题
  7. java学习(138):异常处理
  8. Asp.Net防止刷新重复提交数据的办法
  9. eclips断点调试
  10. opencv实现移动速度计算
  11. SQL中的交叉连接-cross join
  12. 宝藏平台——阿里云云效DevOps
  13. 编程辅助工具推荐:图片工具snipaste
  14. python编程1-win7上运行python
  15. 来华留学生统计数据集(2018-2019年)
  16. 2000-2020年上市公司环保投资数据(含原始数据和stata代码)
  17. 鼠标爱心的html代码,网页js代码鼠标点击爱心特效(富强、自由、爱国、敬业、友善)...
  18. mysql 整理 是什么意思_MySQL问答整理
  19. 怎么利用LinkedIn快速搜索国外客户资源?
  20. 魔百盒MG101通刷固件及教程(当贝桌面)

热门文章

  1. SpringBoot入门详解源码分析
  2. Java读取文件时第一行出现乱码“?”问号
  3. 【三分钟讲清区块链/比特币】之一:区块链入门教程
  4. [深度学习] 自然语言处理 --- Self-Attention(三) 知识点与源码解析
  5. 【Ubuntu-ROS】ubuntu16.04(18.04)ROS安装配置与卸载
  6. __asm__ __volatile__ GCC的内嵌汇编语法 ATT汇编语言语法(Z)
  7. 浓缩摘要_浓缩咖啡的收益递减
  8. 在县城投资买一辆出租车,一个月能收入多少钱?
  9. 逾期了,如何消除不良记录?
  10. ML2 配置 OVS VxLAN - 每天5分钟玩转 OpenStack(146)