惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
I
InfoQ
H
Help Net Security
GbyAI
GbyAI
博客园 - 叶小钗
Recent Announcements
Recent Announcements
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
Y
Y Combinator Blog
L
LangChain Blog
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
F
Fortinet All Blogs
G
Google Developers Blog
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
博客园 - Franky
D
Docker
Jina AI
Jina AI
罗磊的独立博客

博客园 - Kangaroo

IList<T>与Xml互相转换 jQTreeTable在Asp.net中的应用 通用附件上传方法 window.createPopup()创建菜单 - Kangaroo - 博客园 客户端全部选中或取消DataGrid中的CheckBox 事务的回滚设置(SET XACT_ABORT) 获取所有命名的服务器变量的名称和值 服务端返回操作结果消息的方法 - Kangaroo - 博客园 Treeview的文件目录配置 - Kangaroo - 博客园 用层(DIV)来实现弹出窗口 一个实用的表格(锁定表头,可调整单元格大小,可排序) showModalDialog()、showModelessDialog()方法使用详解 SQL Server .NET Framework 数据提供程序连接池 iBATIS.NET 学习笔记(十一) iBATIS.NET 学习笔记(十) iBATIS.NET 学习笔记(九) iBATIS.NET 学习笔记(七) iBATIS.NET 学习笔记(六) iBATIS.NET 学习笔记(五)
iBATIS.NET 学习笔记(八)
Kangaroo · 2006-07-19 · via 博客园 - Kangaroo

在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 窗体设计器生成的代码
        
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();
        }

    }

}