<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<center >
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="简单留言版" Font-Bold="True" Font-Size="XX-Large" ForeColor="Red"></asp:Label>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/MsgBoard.mdb" SelectCommand="SELECT * FROM [post]"></asp:AccessDataSource>
<asp:DataList ID="DataList1" runat="server" CellPadding="4" DataKeyField="postid"
DataSourceID="AccessDataSource1" ForeColor="#333333">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<ItemTemplate>
<table border="1" style="width: 947px; height: 351px; background-color: gainsboro;">
<tr>
<td style="width: 200px; text-align: left;">
第<asp:Label ID="lblID" runat="server" Text='<%# Eval("postid") %>'></asp:Label>
楼</td>
<td style="width: 200px; text-align: left;">
用户名:
<asp:Label ID="lblName" runat="server" Text='<%# Eval("name") %>'></asp:Label></td>
<td style="width: 547px; text-align: left;">
主题:
<asp:Label ID="lblSubject" runat="server" Text='<%# Eval("subject") %>' ForeColor="ControlText"></asp:Label></td>
</tr>
<tr>
<td colspan="3" style="height: 161px">
<asp:TextBox ID="tbMessage" runat="server" Height="161px" Text='<%# Eval("message") %>'
Width="937px" BackColor="ActiveBorder" ReadOnly="True" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td colspan="3" style="height: 23px; text-align: right;">
IP地址是:<asp:Label ID="Label2" runat="server" Text='<%# Eval("ip") %>'></asp:Label>发布时间:<asp:Label ID="lblIpaddress" runat="server" Text='<%# Eval("date") %>'></asp:Label></td>
</tr>
</table>
<br />
</ItemTemplate>
<AlternatingItemStyle BackColor="White" ForeColor="#284775" />
<ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderTemplate>
这个是刚做的留言版
</HeaderTemplate>
<FooterTemplate>
完了
</FooterTemplate>
</asp:DataList></div>
<div style="z-index: 101; left: 12px; width: 974px; position: static; top: 559px;
height: 500px" >
<table style="width: 752px; height: 354px">
<tr>
<td colspan="3" style="text-align: center; height: 20px;">
发表新主题</td>
</tr>
<tr>
<td style="width: 37px; height: 26px; text-align: left;">
姓名:</td>
<td colspan="2" style="width: 592px; height: 26px; text-align: left;">
<asp:TextBox ID="TextBox1" runat="server" Width="127px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 37px; height: 26px; text-align: left;">
主题:</td>
<td colspan="2" style="width: 592px; height: 26px; text-align: left;">
<asp:TextBox ID="TextBox2" runat="server" Width="272px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td colspan="3" style="text-align: left">
<asp:TextBox ID="TextBox3" runat="server" Height="257px" Width="658px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td colspan="2" style="width: 592px">
</td>
<td style="width: 76px">
<asp:Button ID="Button1" runat="server" Text="提交" Width="236px" OnClick="Button1_Click" /></td>
</tr>
</table>
</div>
</form></center>
</body>
</html>
CS文件
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
}
protected void Button1_Click(object sender, EventArgs e)
...{
string strName = this.TextBox1.Text;
string strSubject = this.TextBox2.Text;
string strMsg = this.TextBox3.Text;
string strIp = Request.UserHostAddress.ToString();
string strDate = System.DateTime.Now.ToString();
string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:ASP.NET网站设计LeavewordsApp_DataMsgBoard.mdb;Persist Security Info=True";
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = strConnection;
OleDbCommand cmd = new OleDbCommand ();
cmd.CommandText = "insert into post(name,subject,message,[date],ip)Values('"+strName +"','"+strSubject+ "','"+strMsg +"','"+strDate +"','"+strIp+"')" ;
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
Response .Redirect ("Default.aspx");
}
}
只有这些