昨天的asx 版本的栏目管理和以前的 留言版的程序自从推出以后,反响不错,但是很多网友纷纷提出了新的问题,他们认为 这两个程序其实只是 asp 文件简单的升级到aspx 文件,大家并没有从这些程序中看出aspx的新的特征,纷纷要求 豆腐 使用aspx 的特性来制作一个 aspx 版本的程序,还有的 朋友要求 编程的语言不要再 使用 vb,而是使用c# 语句,其实 ms 推荐的语言是 vb,不过为了 照顾大家学习新知识的渴望,豆腐 又 推出了这个以 纯粹的 aspx 特性+c# 语言制作的 栏目管理程序,下载会在 很快制作完毕。
现在首先看看 这个新的 add.aspx
<%@ assembly name="system.net" %>
<%@ import namespace="system.io" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sql" %>
<script language="c#" runat=server>
protected void page_load(object src, eventargs e){
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 * from lanmuclass order by classid";
dbcomm = new sqlcommand(strsql, conn);
dbcomm.activeconnection.open();
dbcomm.execute(out dbread);
while(dbread.read()){
//这个程序是 在 dropdownlist 的 显示和value 不一致的时候使用
listitem li = new listitem();
li.text = dbread["classname"].tostring();
li.value = dbread["classid"].tostring();
selclass.items.add(li);
}
//如果 显示 和 value 一直的话,则简单的这样就可以了
selfrom.items.add("原创");
selfrom.items.add("转载");
selfrom.items.add("翻译");
selfrom.items.add("资料整理");
//如果不在<asp:textbox 中设置 textmode 属性,也可以这样设置
//txtpass.textmode = textboxmode.password;
}
</script>
<html>
<head>
<title>增加文章</title>
<link rel="stylesheet" type="text/css" href="/doufu.css">
</head>
<body>
<form action="dosaveadd.aspx" method=post>
<asp:table id="tabletest" width=100% gridlines="both" runat="server" horizontalalign="center" font-name="verdana" font-size="8pt" cellpadding=15 cellspacing=0>
<asp:tablerow runat=server>
<asp:tablecell width=20%>呢称</asp:tablecell>
<asp:tablecell width=30%><asp:textbox id="txtname" runat=server /></asp:tablecell>
<asp:tablecell width=20%>密码</asp:tablecell>
<asp:tablecell width=30%><asp:textbox id="txtpass" textmode = password runat=server /></asp:tablecell>
</asp:tablerow>
<asp:tablerow runat=server>
<asp:tablecell width=20%>文章类别</asp:tablecell>
<asp:tablecell width=30% colspan=3><asp:dropdownlist id=selclass runat=server /></asp:tablecell>
</asp:tablerow>
<asp:tablerow runat=server>
<asp:tablecell width=20%>发表类别</asp:tablecell>
<asp:tablecell width=30% colspan=3><asp:dropdownlist id=selfrom runat=server /></asp:tablecell>
</asp:tablerow>
<asp:tablerow runat=server>
<asp:tablecell width=20%>文章标题</asp:tablecell>
<asp:tablecell width=30% colspan=3>
<asp:textbox id="txttitle" runat=server />
<asp:button id="cmddo" runat=server text="确定增加" />
</asp:tablecell>
</asp:tablerow>
<asp:tablerow runat=server>
<asp:tablecell width=20%>文章内容</asp:tablecell>
<asp:tablecell width=30% colspan=3><asp:textbox id="txtcontent" textmode=multiline rows=20 cols=40 runat=server /></asp:tablecell>
</asp:tablerow>
</asp:table>
</form>
</body>
</html>
这里的这个程序很简单,但是他用到了 aspx 的一些特殊的属性,同时 由于 c# 是 区分大小写的 语言,所以大家在 从 vb 转到 c# 的时候 一定要非常的小心。
dosaveadd.aspx文件的内容:
<%@ assembly name="system.net" %>
<%@ import namespace="system.io" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sql" %>
<script language="c#" runat=server>
protected void page_load(object src, eventargs e){
string strconn;
sqlconnection conn;
hashtable cfg=new hashtable();
cfg = (hashtable)context.getconfig("appsettings");
strconn=cfg["conn"].tostring();
conn = new sqlconnection(strconn);
string strname=request.form["txtname"].tostring();
string strpass=request.form["txtpass"].tostring();
if(strname==""){
showmsg.text="对不起,用户名称是 闭填项目";
return;
}
string strsql;
//首先校验用户和密码是否正确
sqldatareader dbread;
strsql="select userpassword from bbsuser where username='" + strname + "'";
sqlcommand sqlcmd=new sqlcommand(strsql,conn);
sqlcmd.activeconnection.open();
sqlcmd.execute(out dbread);
if(!dbread.read()){
showmsg.text="对不起,这个用户不存在!";
return;
}
if(dbread["userpassword"].tostring()!=strpass){
showmsg.text="对不起,用户名称和用户密码不匹配!";
return;
}
sqlcmd.activeconnection.close();
//密码匹配,将用户输入的文本信息保存到数据库中
//因为是 演示 程序,所以就没有 检验 标题和内容 的合法性
string strclassid=request.form["selclass"];
string strselfrom=request.form["selfrom"];
string strtitle=request.form["txttitle"];
string strcontent=request.form["txtcontent"];
strsql="insert into lanmu(classid,title,content,dtime,userid,isuse,viewnum,selfrom)values(";
strsql=strsql + "" + strclassid + ",'" + strtitle + "','" + strcontent + "',";
strsql=strsql + "getdate(),'" + strname + "','0',0,'" + strselfrom + "')";
sqlcmd =new sqlcommand(strsql,conn);
sqlcmd.activeconnection.open();
sqlcmd.executenonquery();
//虽然系统可以自动关闭这个command对象,但是最好还是自己关闭一下
sqlcmd.activeconnection.close();
}
</script>
<html>
<head>
<title>增加文章</title>
<link rel="stylesheet" type="text/css" href="/doufu.css">
</head>
<body>
<asp:label id=showmsg text="恭喜,恭喜,您的文章已经添加到了数据库中!" runat=server />
</body>
</html>
其实,这个 dosaveadd.aspx 文件其实是 可以不用的,我们只要在 add.aspx 的 cmddo 上处理他的onclick 事件就可以了,程序是 一样的,给大家一种新的 选择,不是更好吗?
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 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器