reply2.aspx
来自「《精通ASP.NET网络编程》附带实例」· ASPX 代码 · 共 162 行
ASPX
162 行
<%@Page Language="C#" Debug="True"%>
<%@Import Namespace="System"%>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
<html>
<head>
<title>Post New Topic.</title>
<script Language="C#" runat="server">
DataSet ds ,rs;
DataRow dr ;
string postid ;
public void Page_Load(object sender , EventArgs e)
{
if(!Page.IsPostBack)
{
postid = Request.Params["postid"] ;
if(postid!=null)
{
string strConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+Server.MapPath("board.mdb") ;
OleDbConnection myConn = new OleDbConnection(strConn) ;
//选出主题记录
string strCon ="SELECT subject, name, email, message ,date FROM newpost WHERE postid="+postid ;
OleDbDataAdapter myCommand =new OleDbDataAdapter(strCon,myConn);
ds = new DataSet();
myConn.Open();
myCommand.Fill(ds,"newpost") ;
dr = ds.Tables["newpost"].Rows[0] ;
subject.Text="Re:"+dr["subject"].ToString() ;
//选出对该主题的回复记录
strCon ="SELECT name , email, subject, message ,date FROM reply WHERE postid="+postid ;
OleDbDataAdapter myCommand2 =new OleDbDataAdapter(strCon,myConn);
rs = new DataSet() ;
myCommand2.Fill(rs, "reply") ;
strCon ="SELECT views FROM newpost WHERE postid = "+postid ;
OleDbCommand vicomm = new OleDbCommand(strCon, myConn) ;
OleDbDataReader reader ;
reader = vicomm.ExecuteReader();
reader.Read() ;
int i = reader.GetInt32(0) ;
i++ ;
reader.Close() ;
//更新该主题的点击次数
strCon ="UPDATE newpost SET views = "+i+" WHERE (postid= "+postid+")" ;
vicomm.CommandText = strCon ;
vicomm.ExecuteNonQuery() ;
myConn.Close();
}
}
}
public void Submit_Click(Object sender, EventArgs e)
{
postid = Request.Params["postid"] ;
if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!=""){
//将对该主题的回复提交到postmessage1.aspx页面
DateTime now = DateTime.Now ;
errmess.Text="" ;
string req = "name="+System.Web.HttpUtility.UrlEncode(name.Text, System.Text.Encoding.UTF8);
req+="&&email="+System.Web.HttpUtility.UrlEncode(email.Text, System.Text.Encoding.UTF8);
req+="&&subject="+System.Web.HttpUtility.UrlEncode(subject.Text, System.Text.Encoding.UTF8);
req+="&&ip="+System.Web.HttpUtility.UrlEncode(Request.UserHostAddress.ToString(), System.Text.Encoding.UTF8);
req+="&&date="+System.Web.HttpUtility.UrlEncode(now.ToString(), System.Text.Encoding.UTF8);
req+="&&newpost="+System.Web.HttpUtility.UrlEncode("no", System.Text.Encoding.UTF8);
req+="&&previd="+ System.Web.HttpUtility.UrlEncode(postid, System.Text.Encoding.UTF8);
req+="&&message="+ System.Web.HttpUtility.UrlEncode(message.Text, System.Text.Encoding.UTF8);
Response.Redirect("postmessage2.aspx?" + req);
}
else
{
errmess.Text="你还有一些内容没填 !" ;
}
}
</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" -->
<br>
<div align=center>
<table border=0 width=80% cellspacing=2>
<tr class=fohead>
<th width=20%>作者</th>
<th width=80%>内容</th>
</tr>
<tr class=folight>
<td rowspan=2 align="center">
<%= "<a href=mailto:"+dr["email"]+">"+dr["name"]+"</a>" %>
<br> <font size=1><%= dr["date"]%>
<br> <%= dr["date"]%></font>
</td>
<td><b>主题: </b><%=dr["subject"] %></td>
</tr>
<tr class=folight>
<td><pre><%=dr["message"] %></pre> </td>
</tr>
<% //列出对主题的所有回复记录
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"]%>
<br><%= rd["date"]%></font>
</td>
<td><pre><%=rd["message"] %></pre> </td>
</tr>
<%
}
}
%>
</table>
</div>
<h3 align="center" class="fodark"><a href=forum2.aspx>返回</a>
<br>回复该篇文章
</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>回复</b></td>
</tr>
<tr class="folight" >
<td>大名:</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> 主题:</td>
<td><asp:textbox test="" id="subject" width=200 runat="server"/>
<font color=#ff0000>*</font>
</td>
</tr>
<tr class="folight">
<td>内容 :</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="提交">
</asp:Button>
</td>
</tr>
</table>
</form>
<br><br><!-- #Include File="footer.inc" -->
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?