reply.aspx 浏览贴子内容及回复

2) reply.aspx : The topic viewing and replying page

<%@ Page Language="C#" EnableSessionState="False" Debug="True" %>
<%@ Import Namespace="System" %>
<%@ Assembly Name="System.Data" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
<html><head>
<title>Post New Topic.</title>
<%-- These are the imported assemblies and namespaces needed --%>
<script Language="C#" runat="server">
  DataSet ds ,rs;
  DataRow dr ;
  string postid ;
  public void Page_Load(object sender , EventArgs e)
  {
     //Check if the page is Post Back
     if(!Page.IsPostBack)
    {
       //Get the postid from the Query string
       postid = Request.Params["postid"] ;
       if(postid!=null)
      {
         //Database connection string. Change the path to the database file if you have some other path where
         //you are saving your Database file
         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 the records from the newpost table
         string strCon ="SELECT subject, name, email, message ,date  FROM newpost WHERE postid="+postid ;
          //set a ADODataSetCommand
         ADODataSetCommand myCommand =new ADODataSetCommand(strCon,myConn);
         ds = new DataSet();
         //Don't ever forget to open the Connection
         myConn.Open();
         //Fill the DataSet
         myCommand.FillDataSet(ds,"newpost") ;
         //Get the Row at position '0' and store it in a DataRow object
         //Why row at position '0' ? Since there can only be one record with the given postid remember !!
         //Why put into a DataRow ? Its easy to access data from a DataRow
         dr = ds.Tables["newpost"].Rows[0] ;
         //Get the "subject" from the DataRow and set it up in the post reply form's subject field
         subject.Text="Re:"+dr["subject"].ToString() ;
         //Select the replies to the post from the reply table
         strCon ="SELECT name , email, subject, message ,date FROM reply WHERE postid="+postid ;
         //Make a new ADODataSetCommand and DataSet for the reply table
         ADODataSetCommand myCommand2 =new ADODataSetCommand(strCon,myConn);
         rs = new DataSet() ;
         //fill the DataSet
         myCommand2.FillDataSet(rs, "reply") ;
         //Code to update the "views" field for the newpost Table
         //Select the views field from the table for a given postid
         strCon ="SELECT views FROM newpost WHERE postid = "+postid ;
         //Make a ADOCommand here since we want a ADODataReader later
         ADOCommand vicomm = new ADOCommand(strCon, myConn) ;
         ADODataReader reader ;
         //execute the statement and create a ADODataReader
         vicomm.Execute(out reader) ;
         //Read the First record (there can only be one record remember !)
         reader.Read() ;
         //Get a "Int32" value from the first Column (we have one column in the reader, check the select statement above)
         int i = reader.GetInt32(0) ;
         //Increase the views count
         i++ ;
         reader.Close() ;
         //Update the newpost table with the new views value
         strCon ="UPDATE newpost SET views = "+i+" WHERE (postid= "+postid+")" ;
         //since we are using the same ADOCOmmand object for this statement too to set the CommandText property
         vicomm.CommandText = strCon ;
         //Since this statement will result in no output we use "ExecuteNonQuery()" method
         vicomm.ExecuteNonQuery() ;
         //close the connection
         myConn.Close();
      }
    }
  }
   // This method is called when the submit button is clicked
   public void Submit_Click(Object sender, EventArgs e)
   {
       //Get the postid
       postid = Request.Params["postid"] ;
       
       //proceed only if all the required fields are filled-in
       if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!=""){
         DateTime now = DateTime.Now ;
         errmess.Text="" ;
        //We have to call the postmessage.aspx page with a query to post the data to the Database.
        //Hence we have to first build the custom query from the Data posted by the user
        //also since we are using a query we have to encode the data 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);
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);
        //Encode "no" to indicate that the post is not a new post but its a reply to a earlier message
        req+="&&newpost="+ System.Web.HttpUtility.UrlEncodeToString("no", System.Text.Encoding.UTF8);
        req+="&&previd="+ System.Web.HttpUtility.UrlEncodeToString(postid, System.Text.Encoding.UTF8);
         //Call the postmessage page with our custom query
         Page.Navigate("postmessage.aspx?" + req);
       }
       else
       {
          errmess.Text="Fill in all the Required Fields !" ;
        }
    }
</script>
<LINK href="mystyle.css" type=text/css rel=stylesheet></head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<%-- Include a header file 'header.inc' --%>
<!-- #Include File="header.inc" -->
<br>
<div align=center>
<table border=0 width=80% cellspacing=2>
<tr class=fohead><th width=20%>Author Name</th>
<th width=80%>Message</th></tr>
<%-- Below I am encapsulating the email of the author over the name of the author
so that when you click on the author a e-mail gets sent to him
Also I am geting the DateTime from the DataBase and Displaying the Date and Time separately --%>   
<tr class=folight><td rowspan=2 align="center"><%= "<a href=mailto:"+dr["email"]+">"+dr["name"]+"</a>" %><br>
<font size=1><%= dr["date"].ToString().ToDateTime().ToShortDateString()  %><br>
<%= dr["date"].ToString().ToDateTime().ToShortTimeString() %></font>
</td>
<td><b>Subject: </b><%=dr["subject"] %></td></tr>
<tr class=folight>
<td><pre><%=dr["message"] %></pre> </td>
</tr>
<%-- Get all the replies to the Original post and show them --%>
<% int no = rs.Tables["reply"].Rows.Count ;
   if(no>0)
   {
      for(int j=0 ;j<no ; j++)
      {
          DataRow rd = rs.Tables["reply"].Rows[j] ;
%>
<tr class=fodark>
<td align="center"><%="<a href=mailto:"+rd["email"]+">"+rd["name"]+"</a>" %><br>
<font size=1><%= rd["date"].ToString().ToDateTime().ToShortDateString()  %><br>
<%= rd["date"].ToString().ToDateTime().ToShortTimeString() %></font>
</td>
<td><pre><%=rd["message"] %></pre> </td>
</tr>
<%
        }
    }
%>
</table>
</div>
<h3 align="center" class="fodark"><a href=forum.aspx>Click Here</a> to go to back to Forum.
<br>Reply to the Above Post.</h3>
<br>
<asp:label id="errmess" text="" style="COLOR:#ff0000" runat="server" />
<form runat="server">
<table border="0"  width="80%" align="center">
<tr >
<td class="fohead" colspan=2><b>Reply to the Post</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><br>
<br><!-- #Include File="footer.inc" -->
</body></html>

时间: 2024-08-04 13:26:18

reply.aspx 浏览贴子内容及回复的相关文章

用排序串字段实现树状结构(例程——保存贴子内容)

排序 程序名称:savelyb.asp程序功能:保存贴子内容 <!-- #include file="lybcon.inc" --><%posttype=request("posttype")pageno=request("pageno")keyid=request("keyid")if keyid="" then keyid=0emailpost=request("emailp

js-怎么将aspx页面指定内容导成excel报表

问题描述 怎么将aspx页面指定内容导成excel报表 我想用JS 或者jquery 做一个导报表功能,求教,要各大浏览器都支持的 解决方案 datatable直接转

jQuery+.net实现浏览更多内容(改编php版本)_jquery

改编自php版本,原文: jQuery+PHP实现浏览更多内容http://www.helloweba.com/view-blog-130.html 这里记录.net 下的实现 一.首先创建数据库表test,并插入一些测试数据: 复制代码 代码如下: go if exists (select * from sysobjects where name='test') drop table [test] go CREATE TABLE [test]( [id] [int] IDENTITY(1,1)

重复打开带参数的aspx网页,内容不自动刷新

问题描述 C#+asp.net+SQLSERVER开发的网站:例如:http://192.168.1.1:8080/worklog/viewWorklog.aspx?id=e54ce87f-e417-4a49-8eb3-ca17c61a56a8这是查看工作日志的页面,如果修改了工作日志的内容,重新打开该页面,页面内容还是老的内容,不会自动刷新变成修改后的内容,请问有没有办法让网页自动刷新 解决方案 解决方案二:viewWorklog.aspx的PageLoad方法里面加上Response.Cac

用排序串字段实现树状结构(例程——显示贴子内容)

排序|显示 程序:disprec.asp功能:显示贴子具体内容 <!-- #include file="lybcon.inc" --><%keyid=request("keyid")rootid=request("rootid")pageno=request("pageno")if rootid=0 then rootid=keyidset guestconn=Server.CreateObject(&quo

纽约时报阅读器订户可免费无限制浏览网站内容

新浪科技讯 7月8日下午消息,在Kindle和Nook电子书阅读器上订阅<纽约时报>的用户现在可以免费无限制地浏览<纽约时报>网站的内容. <纽约时报>在3月末推出收费计划,除非用户每月支付15美元订阅,否则每月只能浏览<纽约时报>20篇文章.在收费计划推出后,Kindle电子书阅读器的制造商亚马逊承诺,所有订购阅读器版<纽约时报>的用户,在未来都可以免费无限制地浏览<纽约时报>网站. <纽约时报>在Kinlde.Nook

php简单浏览目录内容的实现代码_php技巧

如下所示: 复制代码 代码如下: <?php$dir = dirname(__FILE__);$open_dir = opendir($dir);echo "<table border=1 borderColor=red cellpadding=6>";echo "<tr><th>文件名</th><th>大小</th><th>类型</th><th>修改日期<

图解Linux命令:使用ls命令浏览目录内容

让我们打开系统终端,直接在目录中输入 ls 看看会输出什么? 原来 ls 命令罗列出了终端当前目录下的所有文件及目录.我们所看到的用蓝色显示的名称都是目录.当然,所有这些目录中都可能还有子目录和文件.我们想知道这些目录下面还有哪些目录和文件可以使用 -R 参数将它们都显示出来. ls 命令还有许多参数,可以获得更加详细的信息.比如 -1 参数.它可以使目录内的文件和目录每行只显示一个,我们试着在终终端中输入命令:ls -1. 另外还有一个问题是我们的 Linux 系统中也会有隐藏文件,这点与 W

js cookie 实现您最近浏览过内容

 代码如下 复制代码 <script language="javascript" > function set_lpid(name,value) //设置访问过的楼盘id入cookie {    var ids = get_lpid(name);   var Days =30 ;//days*24*60*60*1000;   var exp   = new Date();   exp.setTime(exp.getTime() + Days*24*60*60*1000);