网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.用asp.net写的论坛程序.
.具有自攻击性的代码.
.建立一个广告交换及跟踪系统.
.用ASP建立邮件列表.
.显示页面show.asp--基于web的QQ程.
.嵌入式Web视频点播系统实现方法.
.有关站内模糊查询的源程序! .
.制作我们自己的Ebay(拍卖系统)(7).
.用ASP实现号码转换程序实例.
.动态按钮生成器(下).
.使用JScript.NET创建asp.net页面.
.词语搭配游戏的制作(ASP)二.
.用asp生成wml.
.词语搭配游戏的制作(ASP)三.
.磁盘ID在ASP源码防拷贝中的应用.
.ASP进阶之文章在线管理更新(1).
.让您的主页支持各种浏览设备(AS.
.用ASP实现远程批量文件改名.
.利用ASP在客户端注册DLL文件.
.ASP环境下邮件列表功能的实现 (.

用asp.net写的论坛程序--论坛主页

发表日期:2001-5-14


1) forum.aspx :- The main forum page

<%@ Page Language="C#" Debug="true" %>
<%@ Assembly Name="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>
<html><head>
<title>Welcome to My Forum!</title>
<script language="C#" runat="server" >
//execute this script when the page loads
void Page_Load(Object Src, EventArgs E)
{
//Call the Method to DataBind the DataGrid
Binding() ;
}
//This Method Connects to the Database, and DataBinds the Database to the DataGrid
public void Binding()
{
//String to connect to the database, If your Database is in some other directory then change the path
//To the Database below
string strConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+Server.MapPath(".\\db\\board.mdb") ;
//Make a Connection to the Database
ADOConnection myConn = new ADOConnection(strConn) ;
//String to select records from the Database. newpost Table
//I have used "ORDER BY postid DESC" since I want to show the latest post on the top
//If you remove this clause then the oldest message will be shown first
string strCom = "SELECT postid ,subject ,name ,replies ,views ,date FROM newpost ORDER BY postid DESC" ;
//Open the Connection, Always remember to Open the connection before doing anything else
myConn.Open();
DataSet myDataSet = new DataSet();
//Create a ADODataSetCommand and a DataSet
ADODataSetCommand myCommand =new ADODataSetCommand(strCom,myConn);
//Fill the DataSet
myCommand.FillDataSet(myDataSet,"newpost") ;
//Connection is closed
myConn.Close();
//Set the DataView of the Table "newpost" contained in the DataSet for the DataGrid
DataGrid1.DataSource = myDataSet.Tables["newpost"].DefaultView ;
//DataBind the DataGrid
DataGrid1.DataBind();
}
//This method is called when the DataGrid is Paged (i.e. when you change from Page 1 to Page 2 etc.. )
public void DataGrid_Updt(Object sender, DataGridPageChangedEventArgs e)
{
//Call the Method to Databind
Binding();
}
//This Method is called when the form is submitted to make a new Post
public void Submit_Click(Object sender, EventArgs e)
{
//proceed only if all the required fields are filled-in
if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!=""){
//Get the Current Date and Time
DateTime now = DateTime.Now ;
errmess.Text="" ;
//I am building a custom query which will be used to call the postmessage.aspx page.
//Since it will be a query we have to encode the query into UTF8 format.
//So I get all the fields from the form and encode them into UTF8 format
string req = "name="+ System.Web.HttpUtility.UrlEncodeToString(name.Text, System.Text.Encoding.UTF8);
req+="&&email="+ System.Web.HttpUtility.UrlEncodeToString(email.Text, System.Text.Encoding.UTF8);
req+="&&subject="+ System.Web.HttpUtility.UrlEncodeToString(subject.Text, System.Text.Encoding.UTF8);
//Get the HostAddress of the Author
req+="&&ip="+ System.Web.HttpUtility.UrlEncodeToString(Request.UserHostAddress.ToString(), System.Text.Encoding.UTF8);
req+="&&date="+ System.Web.HttpUtility.UrlEncodeToString(now.ToString(), System.Text.Encoding.UTF8);
req+="&&message="+ System.Web.HttpUtility.UrlEncodeToString(message.Text, System.Text.Encoding.UTF8);
//A 'yes' is used below to tell the postmessage page that this is a new topic post
req+="&&newpost="+ System.Web.HttpUtility.UrlEncodeToString("yes", System.Text.Encoding.UTF8);
//call the postmessage.aspx page and append the query to it.
Page.Navigate("postmessage.aspx?" + req);
}
else
{
errmess.Text="Fill in all the Required Fields before Posting!<br>" ;
}
}
</script>
<LINK href="mystyle.css" type=text/css rel=stylesheet></head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<!-- #Include File="header.inc" -->
<center>
<asp:label id="errmess" text="" style="COLOR:#ff0000" runat="server" />
<asp:Label class=fodark text="<font color=#00000 >Welcome to My Discussion Forum</font>" runat=server />
<br>
<br>
<form method="post" runat="server" ID=Form1>
<%-- The DataGrid settings. Its very interesting how much you can play with it --%>
<asp:DataGrid id=DataGrid1 runat="server" ForeColor="Black"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="DataGrid_Updt" PageSize="20" AllowPaging="True" width="80%" autogeneratecolumns="False">
<property name="PagerStyle">
<asp:DataGridPagerStyle BackColor="Coral" Mode="NumericPages">
</asp:DataGridPagerStyle>
</property>

<property name="AlternatingItemStyle">
<asp:TableItemStyle BorderColor="#FFC080" BackColor="#FF9966">
</asp:TableItemStyle>
</property>

<property name="FooterStyle">
<asp:TableItemStyle ForeColor="White" BackColor="DarkOrange">
</asp:TableItemStyle>
</property>

<property name="ItemStyle">
<asp:TableItemStyle BackColor="Moccasin">
</asp:TableItemStyle>
</property>

<property name="HeaderStyle">
<asp:TableItemStyle Font-Bold="True" ForeColor="White" BackColor="Coral">
</asp:TableItemStyle>
</property>
<%-- I am setting up the Individual columns myself using Templates --%>
<property name="Columns">
<%-- Manipulate the subject entry so that it contains a link to the reply page --%>
<asp:TemplateColumn HeaderText="Subject" itemstyle-width=50%>
<template name="ItemTemplate" >
<asp:Label runat="server" Text='<%#"<a href=reply.aspx?postid="+DataBinder.Eval(Container, "DataItem.postid")+">"
+DataBinder.Eval(Container, "DataItem.subject")+"</a>" %>' ID=Label2></asp:Label>
</template>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Author Name" itemstyle-width=20%>
<template name="ItemTemplate">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' ID=Label3></asp:Label>
</template>
</asp:TemplateColumn>


<asp:TemplateColumn HeaderText="Replies" itemstyle-width=10%>
<template name="ItemTemplate">
<asp:Label runat="server" width=10% Text='<%# DataBinder.Eval(Container, "DataItem.replies") %>' ID=Label4>
</asp:Label>
</template>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Views" itemstyle-width=10%>
<template name="ItemTemplate">
<asp:Label runat="server" width=10% Text='<%# DataBinder.Eval(Container, "DataItem.views") %>' ID=Label5>
</asp:Label>
</template>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Date of Post" itemstyle-width=10%>
<template name="ItemTemplate">
<asp:Label runat="server" width=10% Text='
<%# DataBinder.Eval(Container, "DataItem.date").ToString().ToDateTime().ToShortDateString() %>' ID=Label6>
</asp:Label>

</template>
</asp:TemplateColumn>
</property>
</asp:DataGrid>
<br>
<br>
<asp:Label class=fodark text="<font color=#00000 >Post New Topic</font>" runat=server />
<br>
<table border="0" width="80%" align="center">
<tr >
<td class="fohead" colspan=2><b>Post New Topic</b></td>
</tr>
<tr class="folight" >
<td>Name :</td>
<td ><asp:textbox text="" id="name" runat="server" />   <font color=#ff0000>*</font></td>
</tr>
<tr class="folight">
<td>E-Mail :</td>
<td><asp:textbox text="" id="email" runat="server"/>   <font color=#ff0000>*</font></td>
</tr>
<tr class="folight">
<td> Subject:</td>
<td><asp:textbox test="" id="subject" width=200 runat="server"/>   <font color=#ff0000>*</font>
</td></tr>
<tr class="folight">
<td>Message :</td>
<td>
<asp:TextBox id=message runat="server"
Columns="30" Rows="15" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr class=folight>
<td colspan=2>
<asp:Button class=fodark id=write onClick=Submit_Click runat="server" Text="Submit"></asp:Button></td></tr>
</table>
</form>
</center>
<!-- #Include File="footer.inc" -->
</body></html>

上一篇:用asp.net写的论坛程序 人气:11080
下一篇:用asp.net写的论坛程序--浏览贴及回复 人气:10388
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐