日期:2013-10-30  浏览次数:20364 次

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="" ;