留言板

1.

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值