zoukankan
html css js c++ java
DataList编辑、更新、取消、删除、分页(分页控件AspNetPager.dll)
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.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
"
);
}
查看全文
相关阅读:
1.Math函数对象
1.日期与时间
使用object literal替换switch
Array数组去重
flexbox弹性布局
web移动端一些常用知识
解决网页ICON图标无法显示的问题
观察者模式和发布订阅模式的区别
JS延迟加载的几种方式
前端 api 请求缓存方案
原文地址:https://www.cnblogs.com/puke/p/782182.html
最新文章
python 一致性hash
python is == 的区别
python 遍历字典
二项分布
hbase rowkey设计的注意事项
python多线程 批量下补丁
增强型for循环,用于遍历数组元素
猜数字游戏:在数组中查找是否包含自己输入的值
求数组中最大值和最小值
向数组中插入元素
热门文章
数组综合使用,猜数游戏
计算几位学生的平均分
使用Java的嵌套循环打印出平行四边形、等腰三角形、棱形、矩形的星星图案(Java工程师面试必备)
【基础语法】a++与++a的区别
广州市岑村教练场考科目二,惊险通过,经验总结
excel公式处理成绩表
Console命令,让js调试更简单
标题颜色
1.常用字符对象方法
1.全局函数
Copyright © 2011-2022 走看看