选择显示字体大小

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

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(out dbread);
menucontrol1.sread=dbread;
menucontrol1.intrecstart=intrecstart;
menucontrol1.intreccount=intreccount;
menucontrol1.databind();
menucontrol1.pagebar();
writetable();
}
void writetable(){
tablecell c;
tablerow r;


r = new tablerow(); //生成新的一行
c = new tablecell(); //生成新的一列
c.controls.add(new literalcontrol("序号"));
r.cells.add(c);

c = new tablecell(); //生成新的一列
c.controls.add(new literalcontrol("文章标题"));
r.cells.add(c);

c = new tablecell(); //生成新的一列
c.controls.add(new literalcontrol("阅读次数"));
r.cells.add(c);
tabletest.rows.add(r);
while(menucontrol1.myread()){
r = new tablerow(); //生成新的一行

c = new tablecell(); //生成新的一列
c.controls.add(new literalcontrol(menucontrol1.sread["id"].tostring()));
r.cells.add(c);

//栏目的标题用 hyperlink 表示
hyperlink h=new hyperlink();
h.text=menucontrol1.sread["title"].tostring();
h.navigateurl="viewarticle.aspx?id=" + menucontrol1.sread["id"].tostring();
c = new tablecell(); //生成新的一列
c.controls.add(h);
r.cells.add(c);

c = new tablecell(); //生成新的一列
c.controls.add(new literalcontrol(menucontrol1.sread["viewnum"].tostring()));
r.cells.add(c);

tabletest.rows.add(r);
}
return;
}
</script>
<html>
<head>
</head>

<body>
<asp888:mypagetable id="menucontrol1" runat=server />
<asp:table id="tabletest" width=100% gridlines="both" runat="server" horizontalalign="center" font-name="verdana" font-size="8pt" cellspacing=0 />
</body>
</html>
当然,由于时间的关系,我的这个程序有的功能实现的还是比较粗糙和简单的,相信大家只要在这个程序
的基础上 举一反三,一定可以学习到很多很多的知识。同志们,努力吧!

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons