forum1.aspx
来自「《精通ASP.NET网络编程》附带实例」· ASPX 代码 · 共 154 行
ASPX
154 行
<%@Page Language="VB" Debug="true"%>
<%@Import Namespace="System"%>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
<html>
<head>
<title>欢迎访问!</title>
<script language="VB" runat="server" >
Dim startIndex As Integer
Sub Page_Load(Src As Object,E AS EventArgs)
'当刚载入页面时候执行下面的程序。
If Not IsPostBack Then
startIndex =0
End If
'绑定DataGrid
Binding()
End Sub
'链接数据库,绑定DataGrid
Sub Binding()
Dim Provider, ConnStr As String
Provider = "Microsoft.Jet.OLEDB.4.0;"
ConnStr = "Provider="+Provider+"Data Source="+Server.MapPath("board.mdb")
'进行链接数据库
'从newpost 表中选择记录
Dim strCom As String= "SELECT postid ,subject ,name ,replies ,views ,date FROM newpost ORDER BY postid DESC"
'打开链接
Dim myDataSet As DataSet= new DataSet()
Dim myCommand As OleDbDataAdapter=new OleDbDataAdapter(strCom,ConnStr)
'填充DataSet
myCommand.Fill(myDataSet,"newpost")
'关闭链接
'myConn.Close();
'设置表newpost的DataView
DataGrid1.DataSource = myDataSet.Tables("newpost").DefaultView
'绑定 DataGrid
DataGrid1.DataBind()
End Sub
Sub ChangePage(sender As Object,e As DataGridPageChangedEventArgs)
startIndex = e.NewPageIndex*DataGrid1.PageSize
DataGrid1.CurrentPageIndex = e.NewPageIndex
Binding()
End Sub
'以下是表单提交程序
Sub Submit_Click(sender As Object, e As EventArgs)
'先进行判断
If Page.IsValid And name.Text<>"" And subject.Text<>"" And email.Text<>"" Then
'得到当前日期时间
Dim now As DateTime= DateTime.Now
errmess.Text=""
'下面我们用一个字符串向postmessage.aspx传送数据
Dim req As String= "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)
'得到发表者的IP地址
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("yes", System.Text.Encoding.UTF8)
req+="&&message="+System.Web.HttpUtility.UrlEncode(message.Text, System.Text.Encoding.UTF8)
'yes 用来标示这是一个新主题
'向postmessage.aspx传值.
Response.Redirect(("postmessage1.aspx?" + req))
Else
errmess.Text="对不起,您还有些信息没填!<br>"
End If
End Sub
</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" -->
<center>
<asp:label id="errmess" text="" style="COLOR:#ff0000" runat="server" />
<asp:Label class=fodark text="<font color=#00000 >欢迎访问本站讨论区,您可以发表您的看法! </font>" runat=server />
<br>
<br>
<form method="post" runat="server" ID=Form1>
<!-- 设置 DataGrid -->
<asp:DataGrid id=DataGrid1
runat="server"
ForeColor="Black"
PagerStyle-Mode="NumericPages"
Headerstyle-BackColor="#AAAADD"
AlternatingItemStyle-BackColor="#FFFFCD"
OnPageindexChanged="ChangePage"
PageSize="10"
AllowPaging="True"
Width="80%"
Font-Name="Verdana"
Font-Size="8pt"
autogeneratecolumns="False">
<Columns>
<asp:HyperLinkColumn
HeaderText="标题"
DataNavigateUrlField="postid"
DataNavigateUrlFormatString="reply1.aspx?postid={0}"
DataTextField="subject"
/>
<asp:BoundColumn HeaderText="作者" itemstyle-width=10% DataField=name/>
<asp:BoundColumn HeaderText="回复" itemstyle-width=10% DataField=replies/>
<asp:BoundColumn HeaderText="点击次数" itemstyle-width=15% DataField=views/>
<asp:BoundColumn HeaderText="发表日期" itemstyle-width=25% DataField=date/>
</Columns>
</asp:DataGrid>
<br>
<br>
<asp:Label class=fodark text="<font color=#00000 >发表新作</font>" runat=server />
<br>
<table border="0" width="80%" align="center">
<tr>
<td class="fohead" colspan=2>发表新作</td>
</tr>
<tr class="folight" >
<td>大名 :</td>
<td>
<asp:textbox id="name" runat="server"/>
<font color=#ff0000>*</font>
</td>
</tr>
<tr class="folight">
<td>E-Mail :</td>
<td>
<asp:textbox id="email" runat="server"/>
<font color=#ff0000>*</font>
</td>
</tr>
<tr class="folight">
<td> 主题:</td>
<td>
<asp:textbox 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>
</center>
<!-- #Include File="footer.inc" -->
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?