一个小的留言版

本文介绍了一个简单的ASP.NET留言版应用程序的实现过程。该应用使用C#作为后端语言,通过Access数据库存储用户留言信息,并利用DataList控件展示留言记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

<%...@ 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>
                
&nbsp;<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");

    }
}

  

只有这些

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值