当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 使用纯粹的asp+语言制作的栏目管理(二)

ASP.NET
如何在ASP.NET中使用SmtpMail发送邮件
在VB.NET中利用Split和Replace函数计算字数
Attribute应用:简化ANF自定义控件初始化过程
ASP.NET 2.0移动开发入门之使用样式
ASP.NET 2.0中使用OWC生成图表
ASP.NET 2.0中控件的简单异步回调
一个无法捕获ADO.NET Dataset的内存错误
深入解读ADO.NET2.0的十大最新特性
.Net平台下的分布式缓存设计
ASP.NET全局异常处理浅析
ASP.NET 2.0中文验证码的实现
浅析.NET平台编程语言的未来走向
.net 框架程序设计收藏
使用ASP.NET MVC Futures 中的异步Action
详解.NET中的XmlReader与XmlWriter
关于.NET中的Server push技术
asp.net页面执行机制
对比JSP和ASP.NET的存储过程
.NET 4.0不会包含System.Shell.CommandLine
ASP.NET十个有效性能优化的方法

ASP.NET 中的 使用纯粹的asp+语言制作的栏目管理(二)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 96 ::
收藏到网摘: n/a

http://www.asp888.net 豆腐技术站

昨天我们看了 豆腐利用 asp.net 的特性作的 栏目管理的程序的第一部分,在今天的第二部分中,豆腐
将把 昨天我们录入界面录入的数据显示出来,并且在这个部分,专门做了一个 用来进行分页管理的一个
Pagelet,通过这个pagelet 我们将 Select 出来的记录进行了分页的处理,并且复习了我们以前的文章如何在asp+ 中使用自定义的pagelet
通过这个程序,我们将会学习到在 asp.net 的编程中的一些中级的技术(其实更为高级的技术,我们在目前)
的学习和应用的过程中,似乎还没有用到!不对,不对,是豆腐没有用到:)
下面我们首先来看看我们作的这个ascx文件:也叫用户自定义组件文件
c.ascx:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<% @ Import Namespace="System.Drawing" %>
<script runat=server language="C#">
public SQLDataReader sRead; //这个是绑定的数据
public int intPageCount=5; //这个是每页需要显示的数据的多少 默认是10
public int intRecStart=0; //这个是当前数据的 起使位置, 默认是 0
public int intCurrentRow=0; //当前的Row 指针所在的位置
public int intRecCount; //当前的这个查询的记录总数

public void DataBind(){
int i;
for(i=0;i<intRecStart;i++){
sRead.Read();
}
}
public String GetVal(String strName){
sRead.Read();
return sRead[strName].ToString();
}
public bool MyRead(){
if(!sRead.Read())
return false;
if(intCurrentRow==intPageCount)
return false;
intCurrentRow++;
return true;
}
public void PageBar(){
TableCell c;
TableRow r = new TableRow();
c= new TableCell();
int ii=intRecCount;
//(ArrayList)sRead;
String strWrite;
if(intRecStart==0){
strWrite="首页 上页";
}
else
{
strWrite="<a href='c.aspx?start=0'>首页</a> <a href='c.aspx?start=" + (intRecStart-intPageCount).ToString() + "'>上页</a>";
}
if((intRecStart+intPageCount)>ii){
strWrite= strWrite + " 首页 上页";
}
else{
strWrite= strWrite + "<a href='c.aspx?start=" + (intRecStart+intPageCount).ToString() +"'>下页</a> <a href='c.aspx?start=" + (intRecStart+intPageCount).ToString() + "'>末页</a>";
}
c.Controls.Add(new LiteralControl(strWrite));
r.Cells.Add(c);

c = new TableCell(); //生成新的一列
c.Controls.Add(new LiteralControl("共有记录" + ii.ToString()));
r.Cells.Add(c);

Table1.Rows.Add(r);
}
</script>
<asp:Table id="Table1" GridLines="Both" HorizontalAlign="Center" Font-Name="Verdana" Font-Size="8pt" width=100% Runat="server"/>
然后,我们可以通过语句:
<%@ Register TagPrefix="asp888" TagName="myPageTable" Src="c.ascx" %>
可以把c.ascx 文件加入到 任意一个aspx 文件中,而且,我们可以在 aspx 文件中对 我们的这个 ascx 文件中的 public 定义的
参数进行Get 和 Set 的操作,就如同 操作<asp:TextBox> 的属性和方法是一样的,大家在这里一定要特别注意
<asp888:myPageTable id="menuControl1" runat=server />,这个就是我们在 通过 <% Register >中定义的PreFix 和 TagName
来组成的,这样我们通过这个程序,模拟了DataGrid 的 DataBind 的操作,同时也实现了分页的自动化
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<%@ Register TagPrefix="asp888" TagName="myPageTable" Src="c.ascx" %>
<script runat=server language="C#">
protected void Page_Load(Object Src, EventArgs E){
int intRecStart=Request.QueryString["start"].ToInt16();
SQLDataReader dbRead;
SQLCommand dbComm;
String strSQL;
String strConn;
SQLConnection conn;
Hashtable Cfg=new Hashtable();
Cfg = (Hashtable)Context.GetConfig("appsettings");
strConn=Cfg["Conn"].ToString();
conn = new SQLConnection(strConn);
//首先得到记录总数
strSQL="select count(*) from lanmu";
dbComm = new SQLCommand(strSQL, conn);
dbComm.ActiveConnection.Open();
dbComm.Execute(out dbRead);
dbRead.Read();
int intRecCount=dbRead.GetInt32(0);
dbComm.ActiveConnection.Close();
strSQL="select * from lanmu order by id desc";
dbComm = new SQLCommand(strSQL, conn);
dbComm.ActiveConnection.Open();
dbComm.Execute(o