forum.aspx 论坛主页

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>

时间: 2024-05-01 14:53:44

forum.aspx 论坛主页的相关文章

用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"

asp+的论坛列表程序---代码部分

asp+|程序 原作者: 雨晨asp+的论坛列表程序---代码部分 -------------------------------------------------------------------------------- [bigeagle] 于 2000-11-13 15:38:57 加贴在 Joy ASP ↑: /////////////////////////////////////////////////////////////////////////////// // // F

用asp.net写的论坛程序

asp.net|程序 这是一个用asp.net写的论坛程序,虽然简单但可以运行.这个程序的编程思想其实还是基本延续了asp的方式,如果让那只大鸟儿看见可能要嘘之以鼻.但实际上这种方式对于asp程序向asp.net的快速移植还是有用的.如果你对这种移植不屑那也没办法,这个贴子就算给asp.net刚入门的小虾们开开眼.这个例子包含3部分1)forum.aspx-论坛主页.2)reply.aspx-当在论坛主页中点击一个贴子时调用,显示贴子详细内容.3)postmessage.aspx-上贴时调用,将

分析论坛数据库设计&amp;amp;分析

1,数据库设计 论坛数据库设计还是挺有意思的,按照业务逻辑进行拆分的数据库设计. 首先,如果是一个博客就一个post表记可以了.然后考虑到论坛数据量比较大,所以在设计上有优化. 论坛把数据库分成3个数据表,这样在访问不同页面的时候都查询很快. 数据库表参考discuz 数据库设计: 只是挑了些相关字段,没有把所有字段列出了. --论坛板块表 CREATE TABLE forum ( fid mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `name`

蜘蛛侠论坛 2.0 源代码发布

上次发布了1.0版本,经过两个月的测试,发现和改进了不少问题. 因为今后打算全面开始接触学习ASP.NET MVC源代码和jquery,打算今后用这两个框架打造蜘蛛侠论坛3.0版.所以,今天发布蜘蛛侠论坛基于ASP.NET 2.0 WebForm技术开发的最终版本. 我为这个论坛倾注了很多的个人时间,目的就是希望它功能不断完善,架构不断改进,安全性能不管提升.我想任何事情不能看表面,我在做这个论坛的时候学习过很多有名的开源论坛社区,比如国外的DNN,CommunityServer,或者国内的Di

改动网论坛顶端和底端flash的方法

由于动网论坛把顶端和底端的flash全部弄成自己的广告,而且不能在后台改动,这点 确实有点过分哦~~,真好有同学要我帮他改下这两个flash,所以研究了一下动网7.0下面是我的修改过程! 顶端flash:1,把你的flash命名为banner02.swf放到ad目录下 或: 另外也可以不命名为banner02.swf这时你需要修改数据库(data目录下的Dvbbs7.mdb)把表Dv_AdCode中的A_Address字段为0001的那一行A_Adcode字段中的banner02.swf(有两处

用asp.net写的论坛程序--浏览贴及回复

2) reply.aspx : The topic viewing and replying page <%@ Page Language="C#" EnableSessionState="False" Debug="True" %><%@ Import Namespace="System" %><%@ Assembly Name="System.Data" %><

用asp.net写的论坛程序--上贴保存

3) postmessage.aspx :- The page which saved data to the Database <%@ Import Namespace="System" %><%@ Assembly Name="System.Data" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Da

postmessage.aspx 上贴保存

3) postmessage.aspx :- The page which saved data to the Database <%@ Import Namespace="System" %><%@ Assembly Name="System.Data" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Da