留言本(5)回复留言

来源:互联网 发布:做淘宝最好的地方 编辑:程序博客网 时间:2024/04/30 17:04

 页面如下显示:

回复页面是根据所选择的留言进行回复。关键在于怎么获得要进得回复留言的留言主题。就是要获得留言id

源码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="repost.aspx.cs" Inherits="repost" %>

<!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>
    <form id="form1" runat="server">
    <div align="center">
        <table border="1" style="width: 100%; height: 18%" bordercolor="#ffcc33">
            <tr>
                <td align="center"  valign="top" style=" height: 104px;">
                    <asp:Image ID="Image1" runat="server" ImageUrl="~/img/tupian.gif" /></td>
            </tr>
        </table>
   
    </div>
        <div style="text-align: center">
            <table style=" height: 33px">
                <tr>
                    <td style="font-weight: bold; font-size: x-large;  color: #663300">
                        回复留言</td>
                </tr>
            </table>
        </div>
        <div style="text-align: center">
            <table border="1" style="width: 100%; height: 289px" bordercolor="#ffcc00">
                <tr>
                    <td style=" height: 27px; width: 100px;" align="center">
                        留言主题:</td>
                    <td style=" height: 27px" align="left" valign="top">
                        <asp:TextBox ID="TextBox1" runat="server" Height="21px" Width="427px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td style=" height: 24px; width: 100px;" align="center">
                        留言人:</td>
                    <td style=" height: 24px" align="left" valign="top">
                        <asp:TextBox ID="TextBox2" runat="server" Height="20px" Width="359px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*" ControlToValidate="TextBox2"></asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td style=" height: 17px; width: 100px;" align="center">
                        E-mail</td>
                    <td style=" height: 17px" align="left">
                        <asp:TextBox ID="TextBox3" runat="server" Height="18px" Width="387px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*" ControlToValidate="TextBox3" Display="Dynamic"></asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="邮件格式不正确"
                            ValidationExpression="/w+([-+.']/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*" ControlToValidate="TextBox3" Display="Dynamic"></asp:RegularExpressionValidator></td>
                </tr>
                <tr>
                    <td align="center" style=" height: 89px; width: 100px;" valign="top">
                        留言内容:</td>
                    <td style=" height: 89px" align="left" valign="top">
                        <asp:TextBox ID="TextBox4" runat="server" Height="120px" TextMode="MultiLine" Width="475px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox4"
                            ErrorMessage="*"></asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td style="WIDTH: 100px" align="center">
                        头像预览:</td>
                    <td style="width: 100px" align="center" valign="top">
                        <asp:Image ID="Image2" runat="server" Height="90px" Width="90px" /></td>
                </tr>
                <tr>
                    <td align="center" style="width: 100px; height: 36px">
                    </td>
                    <td align="left" style="width: 100px; height: 36px">
                        请选择头像:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1">
                            <asp:ListItem>1.jpg</asp:ListItem>
                            <asp:ListItem>2.jpg</asp:ListItem>
                            <asp:ListItem>3.jpg</asp:ListItem>
                            <asp:ListItem>4.jpg</asp:ListItem>
                            <asp:ListItem>5.gif</asp:ListItem>
                            <asp:ListItem>6.gif</asp:ListItem>
                            <asp:ListItem>7.gif</asp:ListItem>
                        </asp:DropDownList></td>
                </tr>
                <tr>
                  
                    <td align="center" style=" height: 36px" colspan="2">
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        &nbsp; &nbsp; &nbsp; &nbsp;
                        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" />
                        <asp:Button ID="Button2" runat="server" CausesValidation="False" PostBackUrl="~/Default.aspx"
                            Text="返回首页" />
                        <asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label></td>
                </tr>
            </table>
        </div>
        &nbsp;&nbsp;&nbsp;
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="你至少有一信息没有输入"
            ShowMessageBox="True" ShowSummary="False" EnableTheming="False" />
    </form>
</body>
</html>
看看代码吧!

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;

public partial class repost : System.Web.UI.Page
{
 int  Artid;
    protected void Page_Load(object sender, EventArgs e)
    {
        Image2.ImageUrl = "pic/1.jpg";
        Artid = DB.ExecuteScalar("select count(*)from guestbook");
        if (Artid == 0)
        {
            Artid = 1;
        }
        else
        {
            Artid = Artid + 1;
        }
     Int16   ID=Convert.ToInt16 (Request ["id"]);//得到id
     
        string s = DB.ExecuteSca ("select zhuti from guestbook where id="+ID +"");//根所ID获得主题
        TextBox1.Text = "回复"+s;//显示主题
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        DB.ExecuteNonQuery("insert into guestbook values(" + Artid + ",'" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + System.DateTime.Now + "','" + Image2.ImageUrl + "','" + TextBox1.Text + "')");
        Label1.Text = "提交成功!";
    }
 

    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        for (int i = 0; i < DropDownList1.Items.Count; i++)
        {
            if (DropDownList1.Items[i].Selected)
            {

                Image2.ImageUrl = "pic/" + DropDownList1.Items[i].ToString();
            }
        }
    }
}
基本与post.aspx一样,不明白的可以看看post.aspx