- 热门文章:
- · postmessage.aspx 上贴保存
- · .net的几个重要问题
- · 解决问题的方法:(JspFuns与开心的对话录)
- · 控件发布:带日期标注的日历控件。
- · 续上文:由于16K的限制,只能再接一节了。
- · 为什么我在中文win2000+sp1上装的vs.net不能创建各种web application,而英...
- · ASP.NET中密码保护,MD5和SHA1算法的使用
- · ASP。NET连SQL7接口源代码?
- · 我对.Net技术中asp.net应用的一点看法
- · 从一个舆论调查的制作谈面向对象的编程思路(一)
- · 从一个舆论调查的制作谈面向对象的编程思路(二)
- · 从一个舆论调查的制作谈面向对象的编程思路(三)
上一篇:forum.aspx 论坛主页 >>
reply.aspx 浏览贴子内容及回复
<%@ 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>
下一篇:postmessage.aspx 上贴保存 >>
相关文章:
- · 从一个舆论调查的制作谈面向对象的编程思路(五)
- · 在asp.net中使用组件,也包括import和asemble的区别
- · 从一个舆论调查的制作谈面向对象的编程思路(四)
- · 分别用DataGrid、Repeater、DataList绑定XML数据的例子
- · 用DataList 控制元件开发的一个简单的留言本程序:
- · .Net边学边讲(二)
- · .Net边学边讲(一)
- · 里面是对一个body的属性进行server的一些设定,不过可以衍生到其他的一些htmlcontrol新手看看,或者有点...
- · 一个实现自定义event的文章。。。我还没有完全摸透。。不知道有没人有兴趣。。新手就不用看了,先学会走...
- · Server.Transfer,Response.Redirect 和 Page.Navigate 的区别
- · ASP.NET发送ICQ消息DIY
- · web页面用水晶报表的例子
- · Creating Custom Portal Modules
- · 几个.net的重要问题
- · SQL命令中DateTime格式参考
- · 关于webcontrol和pagelet的一点看法
- · 关于.net的几个重要问题的bigeagle版本
- · 关于datagrid的使用以及动态修改,以及使用存储过程的介绍
- · 转阿土伯推荐的文章:在 VS.NET 中编写 Web 应用程序(附图)(推荐)
- · 转新技术网:在ASP.NET中使用.NET组件
- · 自己写的一个资料验证的asp.net程序,大家看看吧!
- · 关于在ASP.NET 中进行调试的方法(转载自itpeople),不过我个人对第三招不以为然,有了vs.net还要那个...
- · 菜鸟入门篇---有关ASP.NET的一些基本说明,解释. [页面标识]
- · 我的第一个ASP+程序,如果是新手请进来看吧。谢绝高手。:)
- · Security Hole In ASP.NET Beta 1 (from angryCoder)
- · 关于从toolbox内拖放控件到form时出错的解决办法
- · XML、DataSet、DataGrid结合写成广告管理程序(上)(转载)
- · XML、DataSet、DataGrid结合写成广告管理程序(下)(转载)
- · 我的aspx为什么无法显示中文?
- · web窗口间的互相控制
- · BigEagle的数据库结构(转载,一动手,就轻拿5分)
- · 转雨天妹妹的文章:TreeView的DHTML实现(可以实现拖动效果哟)
- · 吐血奉献:如何搞定DataGrid 分栏的大小(即DataGrid的可视化控制).
- · Is your .NET Code safe?
- · Introduction to .NET Reflection
- · .net里面的数值格式变换
- · Picture Numeric Format Strings(我很难解释大家自己看)
- · 数值变换时的格式化字符举例
