<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="message.aspx.cs" Inherits="message" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DataList ID="DataList1" runat="server" BackColor="DodgerBlue" BorderColor="DeepSkyBlue"
BorderWidth="1px" CellPadding="2" ForeColor="Black" Width="100%" DataSourceID="SqlDataSource1" BorderStyle="Outset">
<FooterStyle BackColor="Tan" />
<SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<ItemTemplate>
<table style="width: 100%; height: 116px">
<tr>
<td rowspan="2" style=" text-align: center; width: 20%;">
<img height="95" src='images/pics/<%#Eval("face") %>.jpg' width="80" style="border-right: #ff6600 thin outset; border-top: #ff6600 thin outset; border-left: #ff6600 thin outset; border-bottom: #ff6600 thin outset" /><br />
<asp:Label ID="lbluserID" runat="server" Text='<%# Eval("userID") %>'></asp:Label></td>
<td style="text-align: left; width: 534px;">
<asp:Label ID="lbltitle" runat="server" Text='<%# Eval("title") %>' Width="348px"></asp:Label>
<img src="images/posttime.gif" />
<asp:Label ID="lbltime" runat="server" Text='<%# Eval("time") %>' Width="125px"></asp:Label>
</td>
</tr>
<tr>
<td style="height: 7px; width: 534px;">
<asp:Label ID="lblcontent" runat="server" Width="531px" Text='<%# Eval("content") %>'></asp:Label><br />
——————————————————<br />
<span style="font-size: 10pt; color: #ff3300;">管理员回复:<asp:Label ID="lblreply" runat="server" Width="438px" Text='<%# Eval("reply") %>'></asp:Label></span></td>
</tr>
</table>
</ItemTemplate>
<AlternatingItemStyle BackColor="PaleGoldenrod" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:saleConnectionString %>"
SelectCommand="SELECT * FROM [message] ORDER BY [id]"></asp:SqlDataSource>
<br />
<table style="width: 100%; border-bottom-color: #ff6600; border-bottom-style: solid;" border="1">
<tr>
<td style="width: 83px; text-align: center;">
请选择头像</td>
<td style="vertical-align: middle; ">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" >
<asp:ListItem>pic1</asp:ListItem>
<asp:ListItem>pic2</asp:ListItem>
<asp:ListItem>pic3</asp:ListItem>
<asp:ListItem>pic4</asp:ListItem>
<asp:ListItem>pic5</asp:ListItem>
<asp:ListItem>pic6</asp:ListItem>
<asp:ListItem>pic7</asp:ListItem>
<asp:ListItem>pic8</asp:ListItem>
<asp:ListItem>pic9</asp:ListItem>
<asp:ListItem>pic10</asp:ListItem>
</asp:DropDownList>
<asp:Image ID="Image1" runat="server" /></td>
</tr>
<tr>
<td style="width: 83px; text-align: center;">
标题</td>
<td style="width: 291px">
<asp:TextBox ID="TextBox2" runat="server" Width="287px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 83px; text-align: center;">
留言内容</td>
<td style="width: 291px">
<asp:TextBox ID="TextBox1" runat="server" Height="56px" TextMode="MultiLine" Width="443px"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="Button1" runat="server" Text="留言" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="取消" /></td>
</tr>
</table>
</asp:Content>
2.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.SqlClient;
public partial class message : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string id = DropDownList1.SelectedItem.Text;
Image1.ImageUrl = "images/pics/" + id + ".jpg";
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["saleConnectionString"].ConnectionString);
string userID = Session["userID"].ToString();
string postime = DateTime.Now.ToShortTimeString();
string text = TextBox1.Text;
string face = DropDownList1.SelectedItem.Text;
string title = TextBox2.Text;
string reply="";
string sql = "insert into [message] values('" + title + "','" + text + "','" + reply + "','" + face + "','" + postime + "','" + userID + "') ";
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
Response.Write("<Script Language=JavaScript>alert(\"发表留言成功!\")</Script>");
}
}