于什么都喜欢自己动手,按捺不住自己写一个高效的分页查询控件。
以前,一直都使用VS.NET 2003和SQL Server 2000,没怎么去接触 VS 2005 和SQL Server 2005。工具版本升级是早晚的事情,于是就开发一个能运行在VS 2005 上的 控件吧。
属先是采用 PowerDesigner 12.0 绘UML图(主要是类图),PowerDesigner 12.0 不支持 C#2.0还无所谓, 让我痛苦的是把类实现interface 里面的属性的get;set生成了方法,比如:
public interface IAAA
{
string ABC
{
get;set;
}
}
public class Test: IAAA
{
public string get_ABC()
{return "";}
public void set_ABC()
{}
}
这个问题希望高手帮忙解决一下,我不希望一个问题在我身上停留太久。
然后,就是编写代码,写了N多行代码啊,由于以前做ASP.net不多,所以速度就慢了点,整整耗费了我一个双休。
一下是.ASPX里的代码:
以下是.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;

public
partial
class
Default : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)

{
//DbHelper.GetDbConnString()方法返回数据库链接字符串
this.WebPaginationSearch1.DbConnString = DbHelper.GetDbConnString();
//设置sql语句
this.WebPaginationSearch1.SqlString = "select * from pub_dict";
//设置分页的排序字段
this.WebPaginationSearch1.PaginationFieldText = "dictid asc";
//设置Url
this.WebPaginationSearch1.WebPageUrl = "Default.aspx?";
//设置分页的查询键(url)
this.WebPaginationSearch1.PaginationKeyName = "idx";
//设置当前页号
int idx= Page.Request.QueryString["idx"]==null ? 1 : int.Parse(Page.Request.QueryString["idx"]);
this.WebPaginationSearch1.CurrentPage = idx;
//这次我采用的是DataReader。
IDataReader dr = this.WebPaginationSearch1.PaginationSearchDataReader();
this.GridView1.DataSource = dr;
//如果要采用DataSet:
//this.GridView1.DataSource = this.WebPaginationSearch1.PaginationSearchDataSet();
this.GridView1.DataBind();
//释放dr
dr.Dispose();
//打印查询统计
this.Label1.Text= string.Format("共{0}页,{1}条记录 / 当前第{2}页",
this.WebPaginationSearch1.GetPageCount().ToString(),
this.WebPaginationSearch1.GetRowCount().ToString(),
this.WebPaginationSearch1.CurrentPage.ToString());
}
}
以前,一直都使用VS.NET 2003和SQL Server 2000,没怎么去接触 VS 2005 和SQL Server 2005。工具版本升级是早晚的事情,于是就开发一个能运行在VS 2005 上的 控件吧。
属先是采用 PowerDesigner 12.0 绘UML图(主要是类图),PowerDesigner 12.0 不支持 C#2.0还无所谓, 让我痛苦的是把类实现interface 里面的属性的get;set生成了方法,比如:
public interface IAAA
{
string ABC
{
get;set;
}
}
public class Test: IAAA
{
public string get_ABC()
{return "";}
public void set_ABC()
{}
}
这个问题希望高手帮忙解决一下,我不希望一个问题在我身上停留太久。
然后,就是编写代码,写了N多行代码啊,由于以前做ASP.net不多,所以速度就慢了点,整整耗费了我一个双休。
一下是.ASPX里的代码:
1
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default"
%>
2
<%
@ Register Assembly="DAF.Components" Namespace="DAF.Components" TagPrefix="cc1"
%>
3
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
4
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
5
<
head
runat
="server"
>
6
<
title
>
无标题页
</
title
>
7
</
head
>
8
<
body
style
="text-align: center"
>
9
<
form
id
="form1"
runat
="server"
><
cc1:WebPaginationSearch
ID
="WebPaginationSearch1"
runat
="server"
PageSize
="5"
/><
br
/>
10
<
asp:Label
ID
="Label1"
runat
="server"
Text
="Label"
/><
br
/>
11
<
asp:GridView
ID
="GridView1"
runat
="server"
BackColor
="LightGoldenrodYellow"
BorderColor
="Tan"
BorderWidth
="1px"
CellPadding
="2"
ForeColor
="Black"
GridLines
="None"
>
12
<
FooterStyle
BackColor
="Tan"
/>
13
<
SelectedRowStyle
BackColor
="DarkSlateBlue"
ForeColor
="GhostWhite"
/>
14
<
PagerStyle
BackColor
="PaleGoldenrod"
ForeColor
="DarkSlateBlue"
HorizontalAlign
="Center"
/>
15
<
HeaderStyle
BackColor
="Tan"
Font-Bold
="True"
/>
16
<
AlternatingRowStyle
BackColor
="PaleGoldenrod"
/>
17
</
asp:GridView
>
18
</
form
>
19
</
body
>
20
</
html
>



2



3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

以下是.CS里的代码:
















































至于页长,组长等其他的信息我就没有一一设置了,就采用了控件的默认配置。
测试了几次,程序都通过了。
控件的表现:
一:外表美观(用户可以自定义外观);
二:查询速度快(采用了SQL 92标准的 Row_Number() 函数);
三:程序的扩展性好(以后和容易的升级和查询别的数据库)。
在应用于一个项目,并不出Bug后,我就发布上来,让高手们指点一二阿。
http://www.cnblogs.com/dagecc/archive/2006/11/13/558724.html