asp.net实现access数据库分页的方法

时间:2021-07-11 23:08:53

asp.net操作access数据库是常见的数据库操作应用,本文就来实例讲解一下asp.net实现access数据库分页的方法。希望对大家的asp.net程序设计能有所帮助。

具体实例代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<divclass="page"id="ctrlRecordPage">
总<asp:LabelID="Zpage"runat="server"Text="1"></asp:Label>页/
<asp:LabelID="Zcount"runat="server"Text="0"></asp:Label>条
<asp:LinkButtonID="start_button"runat="server"onclick="start_button_Click">首页</asp:LinkButton>
<asp:LinkButtonID="up_button"runat="server"onclick="up_button_Click">上一页</asp:LinkButton>
<asp:LinkButtonID="down_button"runat="server"onclick="down_button_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="end_button" runat="server" onclick="end_button_Click">末页</asp:LinkButton>  
每页<asp:TextBoxID="Pagesize"runat="server"Text="10"Width="30px"></asp:TextBox>条
当前<asp:DropDownListID="Pageing"runat="server"AutoPostBack="True"
onselectedindexchanged="Pageing_SelectedIndexChanged"></asp:DropDownList>页
</div>
privatevoidPageing_databird(intvalue)
{
Pageing.Items.Clear();
intzdatapage=Convert.ToInt32(Zpage.Text);
if(zdatapage>0)
{
for(inti=1;i<=zdatapage;i++)
{
Pageing.Items.Add(i.ToString());
}
}
else
{
Pageing.Items.Add("1");
}
if(Pageing.Items.FindByValue(value.ToString())!=null)Pageing.SelectedValue=value.ToString();
if(zdatapage>1)
{
Pageing.Enabled=true;
intdatapageing=Convert.ToInt32(Pageing.SelectedValue);
if(datapageing>1)
{
start_button.Enabled=true;
up_button.Enabled=true;
}
else
{
start_button.Enabled=false;
up_button.Enabled=false;
}
if(datapageing<zdatapage)
{
down_button.Enabled=true;
end_button.Enabled=true;
}
else
{
down_button.Enabled=false;
end_button.Enabled=false;
}
}
else
{
start_button.Enabled=false;
up_button.Enabled=false;
down_button.Enabled=false;
end_button.Enabled=false;
Pageing.Enabled=false;
}
}
protectedvoidstart_button_Click(objectsender,EventArgse)
{
intdatapageing=1;
if(Pageing.Items.FindByValue(datapageing.ToString())!=null)Pageing.SelectedValue=datapageing.ToString();
DataBird();
}
protectedvoidup_button_Click(objectsender,EventArgse)
{
intdatapageing=Convert.ToInt32(Pageing.SelectedValue);
if(datapageing>1)datapageing--;
if(Pageing.Items.FindByValue(datapageing.ToString())!=null)Pageing.SelectedValue=datapageing.ToString();
DataBird();
}
protectedvoiddown_button_Click(objectsender,EventArgse)
{
intdatapageing=Convert.ToInt32(Pageing.SelectedValue);
intzdatapage=Convert.ToInt32(Zpage.Text);
if(datapageing<zdatapage)datapageing++;
if(Pageing.Items.FindByValue(datapageing.ToString())!=null)Pageing.SelectedValue=datapageing.ToString();
DataBird();
}
protectedvoidend_button_Click(objectsender,EventArgse)
{
intzdatapage=Convert.ToInt32(Zpage.Text);
if(Pageing.Items.FindByValue(zdatapage.ToString())!=null)Pageing.SelectedValue=zdatapage.ToString();
DataBird();
}
protectedvoidPageing_SelectedIndexChanged(objectsender,EventArgse)
{
DataBird();
}
protectedvoidDataBird()
{
dc.Setsql="select*fromadlistorderbycreatetimedesc";
DataTabledt=dc.GetDataTable(0);
PagedDataSourcepds=newPagedDataSource();
pds.DataSource=dt.DefaultView;
pds.AllowPaging=true;
intdatapagesize=10;
if(Convert.ToInt32(Pagesize.Text)>0)datapagesize=Convert.ToInt32(Pagesize.Text);
pds.PageSize=datapagesize;
Zcount.Text=pds.DataSourceCount.ToString();
Zpage.Text = pds.PageCount.ToString();
intzpaging=1;
if(Pageing.SelectedIndex>-1)zpaging=Convert.ToInt32(Pageing.SelectedValue);
Pageing_databird(zpaging);
pds.CurrentPageIndex=Convert.ToInt32(Pageing.SelectedValue)-1;
listshow_Repeater.DataSource=pds;
listshow_Repeater.DataBind();
}

相信本文实例能对大家的asp.net程序设计带来一定的启发与灵感。感兴趣的朋友可以进一步完善本文实例,使其功能更加完善,界面更加美观。