Reply.aspx Browse the content of posts and reply

Source: Internet
Author: User
Tags count datetime include mail tostring
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"%>
<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 are have some other path where
You are saving your Database file
String strconn=@ "provider=microsoft.jet.oledb.4.0;D ata 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 is one record with the given PostID remember!!
Why put into a DataRow? It easy to access data from a DataRow
Dr = ds. tables["Newpost"]. Rows[0];
Get the "subject" from the DataRow and set it, 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 datasets 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 "There can only" one record remember!)
Reader. Read ();
Get a ' Int32 ' value from the ' the ' ' in ' the ' the ' 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 would result at no output we use "ExecuteNonQuery ()" Method
Vicomm. ExecuteNonQuery ();
Close the connection
Myconn.close ();
}
}
}
This are 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 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 this post is not a new post but it 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" Required Fields! ";
}
}
</script>
<link href= "Mystyle.css" Type=text/css rel=stylesheet><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 then 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" 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>
&LT;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>

<br>reply to the Above post.<br>
<asp:label id= "errmess" text= "style=" COLOR: #ff0000 "runat=" Server "/>
<form runat= "Server" >
<table border= "0" width= "80%" align= "Center" >
<tr >
&LT;TD class= "Fohead" colspan=2><b>reply to the Post</b></td>
</tr>
<tr class= "Folight" >
<td>name:</td>
&LT;TD ><asp:textbox text= "" id= "name" runat= "Server"/> <font #ff0000 >*</font></td>
</tr>
<tr class= "Folight" >
<td>e-mail:</td>
<td><asp:textbox text= "" id= "email" runat= "server"/> <font #ff0000 color= >
</tr>
<tr class= "Folight" >
<td> subject:</td>
<td><asp:textbox test= "" id= "subject" width=200 runat= "server"/> <font #ff0000 color= >
</td></tr>
<tr class= "Folight" >
<td>message:</td>
<td>
<asp:textbox id=message runat= "Server"
columns= "rows=" textmode= "MultiLine" ></asp:TextBox></td>
</tr>
<tr class=folight>
&LT;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>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.