日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

iBATIS.NET 学习笔记(八)

發布時間:2023/12/13 asp.net 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iBATIS.NET 学习笔记(八) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在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 学习笔记(八)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。