当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用asp.net写的论坛程序--论坛主页

ASP
ASP实例代码:搞个长文章分页代码
说说对象的复制
多个函数验证同一表单
查询某个字段没有值的所有记录的SQL语句怎么写?
ASP实例:一个简单的ASP无组件上传类
ASP实例讲解:用分页符实现长文章分页显示
ASP实例:动态网页中常用的6个ASP程序
ASP实例:词语搭配游戏的制作
ASP实例学习:随机生成文件名的函数
asp实例:测试WEB服务器
ASP实例:计数器程序详解
预防ASP网站被黑 彻底了解ASP木马
分享:XML HTTP Request的属性和方法简介
ASP架设:给每个IIS站点建立一个用户
ASP技巧:判断远程图片是否存在
故障解决:解决ASP脚本运行超时的方法
再说ASP输出N行N列表格
怎么判断一个对象是否已被释放
ASP实现网页打开任何类型文件都保存的方法
ASP技巧:利用函数InstrRev()获取当前文件名

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


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

  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("postmess