分享
 
 
 

用asp.net写的论坛程序

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

这是一个用asp.net写的论坛程序,虽然简单但可以运行。

这个程序的编程思想其实还是基本延续了asp的方式,如果让那只大鸟儿看见可能要嘘之以鼻。但实际上这种方式对于asp程序向asp.net的快速移植还是有用的。如果你对这种移植不屑那也没办法,这个贴子就算给asp.net刚入门的小虾们开开眼。

这个例子包含3部分

1)forum.aspx-论坛主页。

2)reply.aspx-当在论坛主页中点击一个贴子时调用,显示贴子详细内容。

3)postmessage.aspx-上贴时调用,将内容保存入数据库

数据库结构 Table - newpost :This table will contain the New

Topic posted messages

postid (primary key) The unique id for each new topic.

name The name of the author of the message.

email E-mail address of the author.

subject Subject of the message.

ip IP address of the author.

date Date / Time of the Post

message Message posted.

replies Number of replies to the post (if any)

views Number of times the message has been viewed.

Table - reply :This table will contain the Replies made to the new topics.

replyid (primary key) The unique id for each reply.

name Name of the author.

email E-mail address of the author.

subject Subject of the post

ip IP of the author.

date Date / Time of post.

message Message posted.

postid postid from the "newpost" table for which this message is a reply.

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

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=styl

[1] [2] [3] [4] [5] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有