频道直达 - 学院 - 下载 - 交易 - 截图 - 特效 - 字库 - 手册 - 排名-工具 - 繁體
设为首页
加入收藏
联系我们
建站搜索: 虚拟主机  域名注册   常用广告代码      用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发 -> Asp.Net -> 文章内容
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 通过google 赶快来赚..
· [图文] 头像-qq头像(..
· 要10G免费网络硬盘的..
· 注册码大全三
· 注册码大全十
· [图文] 梦幻背景图片..
· [图文] 卡通动物图片..
相关文章
· 用PHP实现标准的IP Whoi..
· ASP实现简单的网页保护
· 谢文表态不会开战 周鸿袆..
· Flash洋葱皮特效模拟(1)..
· 首页设计所应该达到的几..
· 获取汉字的首字母
· 玩转虚拟域名◎+ .
· 不同的ALT
· ADO 光 标 基 础 (1)&am..;
· 為 Microsoft Visual St..
用asp.net写的论坛程序--浏览贴及回复
作者:未知  来源:转载  发布时间:2005-7-20 11:34:53  发布人:acx

减小字体 增大字体

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 --%>
<&#115cript 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 !" ;
}
}
</&#115cript>
<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>



[打 印]
[] [返回上一页] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
未经授权禁止转载、摘编、复制或建立镜像.如有违反,追究法律责任.
免责申明:中国建站之家(www.jz123.cn)上的所有提供下载的软件和资源
均来源于网络,为软件或程序作者提供和网友推荐收集整理而来,仅供学习
和研究使用。如有侵犯你的版权,请立即联系我们,本站将在3个工作日内删除。
粤ICP备05092265号