简易留言板

 
<asp:DataList ID="DataList1" runat="server" Style="position: relative; background-color: #ffcc66; left: 0px; top: 5px;">
                <ItemTemplate>
                            <table border="0" cellpadding="0" cellspacing="0" style="border-top: #e8e8e8 1px solid;
                                left: 1px; width: 457px; position: relative; top: 0px; height: 32px">
                                <tr>
                                    <td style="background-image: url(images/showbj.gif); height: 27px; border-left: #e8e8e8 1px solid;" align="center">
                                        </td>
                                    <td align="right" colspan="2" style="border-right: #e8e8e8 1px solid; background-image: url(images/showbj.gif);
                                        width: 978px; height: 27px; background-color: #66cc66;">
                                        <div style="left: -2px; width: 223px; position: relative; top: 8px; height: 26px;
                                            text-align: left">
                                           发布时间:<%# Eval("留言时间")%></div>
                                    </td>
                                </tr>
                            </table>
                            <table border="0" cellpadding="0" cellspacing="0" style="left: 1px; width: 470px;
                                position: relative; top: 0px; border-right: #e8e8e8 1px solid; border-left: #e8e8e8 1px solid; height: 100%;">
                                <tr>
                                    <td style="width: 50px; border-right: #e8e8e8 1px solid; height: 122px;" align="center">
                                        <div style="width: 100px; position: relative; height: 100px; z-index: 100;">
                                            <img alt="a" style="position: relative; height: 93px;" src='<%# Eval("头像")%>' />
                                            </div>
                                        <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 15px; position: absolute;
                                            top: 107px" Text='<%# Eval("昵称") %>' Width="74px"></asp:Label>
                                    </td>
                                    <td style="width: 316px; border-bottom: #e8e8e8 1px solid; height: 122px">
                                        <div style="left: 7px; width: 337px; position: relative; top: -1px;
                                            text-align: left; height: 82px; z-index: 101; color: #000000;">
                                            <%# Eval("内容")%>
                                            <br />——————————————————<br />
                                            
                                            <table style="z-index: 100; left: 2px; width: 333px; position: absolute; top: 37px">
                                                <tr>
                                                    <td style="width: 100px; color: #ff0033;">管理员回复:<%# Eval("管理员回复")%>
                                                    </td>
                                                </tr>
                                            </table>
                                            </div>
                                        <table style="z-index: 102; left: 115px; width: 342px; position: absolute; top: 98px">
                                            <tr>
                                                <td style="width: 100px; height: 16px;">
                                                    <asp:LinkButton ID="LinkButton1" runat="server" Height="18px" Style="z-index: 100;
                                                        left: 145px; position: absolute; top: 4px" Width="88px" OnClick="LinkButton1_Click">发表新留言</asp:LinkButton>
                                                    <asp:LinkButton ID="lbtnReply" runat="server" CommandArgument='<%# Eval("昵称")+","+Eval("留言时间")%>' OnCommand="lbtnReply_Command" Style="z-index: 101; left: 233px;
                                                        position: absolute; top: 4px" Width="39px">回复</asp:LinkButton>
                                                    <asp:LinkButton ID="lbtnDelete" runat="server" CommandArgument='<%# Eval("昵称")+","+Eval("留言时间")%>' OnCommand="lbtnDelete_Command" Style="z-index: 103; left: 280px;
                                                        position: absolute; top: 3px" Width="41px">删除</asp:LinkButton>
                                                </td>
                                            </tr>
                                        </table>
                                        
                                    </td>
                                </tr>
                               
                            </table>
                        </ItemTemplate>
                        <SeparatorTemplate>
                            <br />                            
                        </SeparatorTemplate>
                    </asp:DataList>

<td align="right" style="height: 26px; width: 496px; text-align: left;">
                    共<asp:Label ID="lblMesTotal" runat="server" Style="position: relative" Text="Label"></asp:Label>条留言 
                    第<asp:Label ID="lblPageCur" runat="server" Style="position: relative" Text="Label"></asp:Label>页 
                    共<asp:Label ID="lblPageTotal" runat="server" Style="position: relative" Text="Label"></asp:Label>页 
                    <asp:Button ID="Button3" runat="server" Style="position: relative" Text="首页" OnClick="Button3_Click" />
                    <asp:Button ID="Button1" runat="server" Style="position: relative" Text="上一页" OnClick="Button1_Click" />
                    <asp:Button ID="Button2" runat="server" Style="position: relative" Text="下一页" OnClick="Button2_Click" />
                    <asp:Button ID="Button4" runat="server" Style="position: relative" Text="尾页" OnClick="Button4_Click" />
                      转到<asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative">
                    </asp:DropDownList> 
                    <asp:Button ID="Button5" runat="server" Style="position: relative" Text="GO" OnClick="Button5_Click" /></td>

后台代码:

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 reply_show : System.Web.UI.Page
{
    string curPage;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.lblPageCur.Text = "1";//不能放到dataGridBind()后面,不然lblPageCur.Text没有被初始化,出错
            dataGridBind();            
        }
    }
    public void dataGridBind()
    {        
        curPage =this.lblPageCur.Text;
        SqlConnection conn = DB.createCon();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "select * from [liuyan] order by 留言时间 desc";
        cmd.Connection = conn;
        SqlDataAdapter sda = new SqlDataAdapter();
        sda.SelectCommand = cmd;
        DataSet ds = new DataSet();
        sda.Fill(ds,"liuyan");
        PagedDataSource pds = new PagedDataSource();
        pds.AllowPaging = true;
        pds.PageSize = 4;
        pds.DataSource = ds.Tables["liuyan"].DefaultView;
        pds.CurrentPageIndex = Convert.ToInt32(curPage) - 1;
        this.lblPageTotal.Text = pds.PageCount.ToString();
        this.Button1.Enabled = true;
        this.Button2.Enabled = true;

        if (curPage == "1")
        {
            this.Button1.Enabled = false;
        }            
        if (curPage == pds.PageCount.ToString())
        {
            this.Button2.Enabled = false;
        }
        this.DataList1.DataSource = pds;
        this.DataList1.DataBind();

        cmd.CommandText = "select count(*) from liuyan";
        this.lblMesTotal.Text = Convert.ToString(cmd.ExecuteScalar());

        int a = pds.PageCount;
        for(int i=1;i<=a;i++)
        {
            this.DropDownList1.Items.Add(i.ToString());
        }
    }

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        LinkButton dele=(LinkButton)(e.Item.FindControl("lbtnDelete"));
        if (dele != null)
        {
            dele.Attributes.Add("onclick","return confirm('确定删除吗?')");
        }
    }

    protected void lbtnDelete_Command(object sender, CommandEventArgs e)
    {
        if(Session["admin"]!=null)
        {
            
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = DB.createCon();
            string[] estr = e.CommandArgument.ToString().Split(',');
            string userID = Convert.ToString(estr[0]);
            string time = Convert.ToString(estr[1]);
            cmd.CommandText = "delete from [liuyan] where 昵称='"+userID+"'and 留言时间='"+time+"'";
            if (cmd.ExecuteNonQuery() > 0)
            {
                Response.Write("<script>alert('删除成功!');window.location=window.location;</script>");
            }
            else
            {
                Response.Write("<script>alert('删除失败!');window.location=window.location;</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('对不起,只有管理员才允许删除留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>");
        }
    }

    protected void lbtnReply_Command(object sender, CommandEventArgs e)
    {
        if (Session["admin"] != null)
        {
            string[] estr = e.CommandArgument.ToString().Split(',');
            string userID = Convert.ToString(estr[0]);
            string time = Convert.ToString(estr[1]);
            Response.Redirect("reply.aspx?userID="+userID+"&time="+time+"");           
        }
        else
        {
            Response.Write("<script>alert('对不起,只有管理员才允许回复留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>"); 
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text)-1);
        dataGridBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text) + 1);
        dataGridBind();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        this.lblPageCur.Text = "1";
        dataGridBind();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        this.lblPageCur.Text = this.lblPageTotal.Text;
        dataGridBind();
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.lblPageCur.Text = this.DropDownList1.SelectedValue;
            dataGridBind();
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("liuyan.aspx");
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值