有缺陷的留言板

 

 

頁面設置:

<%@ PageLanguage="C#"AutoEventWireup="true"CodeBehind="¢??ã?.aspx.cs" Inherits="ajax.¢??ã?" %>

 

<%@ Registerassembly="CKEditor.NET"namespace="CKEditor.NET"tagprefix="CKEditor"%>

 

<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML 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>

    <style type="text/css">

        body

    {

        width:960px;

        height:900px;

        position:relative;

        margin:0px auto;

            top:0px;

            left:0px;

        }

    #content

    {

        width:960px;

        height:900px;

    }

    #liuyan

    {

        width:960px;

        height:281px;

        float:left;

    

    }

   #contents

   {

       width:960px;

       height:558px;

       float:left;

     

      

   }

    </style>

  <%--  ScriptManager.RegisterStartupScript(this,this.GetType(), "","<script>openLayer('test_con3')</script>", false);--%>

 

</head>

<body>

    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate>

     <div id="content">

    <div id="liuyan">

        <CKEditor:CKEditorControl ID="cke" runat="server" Height="202px"></CKEditor:CKEditorControl>

        <br />

 

        <asp:Button ID="btnpl" runat="server" Text="¨¤?" onclick="btnpl_Click" />

    

 

        &nbsp;&nbsp;

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Ì??" />

        </div>

    <div id="contents">

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

            style="text-align: left; margin-top: 100px;" Width="100%" Height="100%">

            <Columns>

                <asp:BoundField DataField="name" HeaderText="®?¨ª" />

                <asp:BoundField DataField="contents" HeaderText="¨²¨Y" />

                <asp:BoundField DataField="time" HeaderText="¢??º¡À?" />

            </Columns>

        </asp:GridView>

        </div>

        <asp:Button ID="btnno1" runat="server" Text="º¡Á°3" onclick="btnno1_Click" />

        <asp:Button ID="btnlast" runat="server" Text="¦?°?°3" onclick="btnlast_Click" />

        <asp:Button ID="btnnext" runat="server" Text="?°?°3" onclick="btnnext_Click" />

        <asp:Button ID="btnmoye" runat="server" Text="?°3" onclick="btnmoye_Click" />

    </div>

    </ContentTemplate>

    </asp:UpdatePanel>

  

    </form>

</body>

</html>

 

後臺代碼:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Data;

 

namespace ajax

{

    public partial class ¢??ã? : System.Web.UI.Page

    {

        intpagesize = 4;

        protectedvoid Page_Load(objectsender, EventArgs e)

        {

 

            if(!IsPostBack)

            {

                ViewState["pageindex"] = "1";

                get();

            }

 

 

            if(Session["name"] == null)

            {

                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "OK","<script type='text/javascript'>alert('?¨²¨¨Ì??ê?¨²?D¢??ê?');</script>");

            }

            else

            {

                Button1.Visible = false;

            }

 

          

          

 

        }

 

        protectedvoid btnpl_Click(objectsender, EventArgs e)

        {

            stringstr = "data source=LENOVO-PC\\SQLEXPRESS;database=MyTest;IntegratedSecurity=true";

            SqlConnectionconn = new SqlConnection(str);

            SqlCommandcomm = new SqlCommand();

            comm.Connection = conn;

            comm.CommandText = "insert into liuyanban (name,contents,time) values(@name,@contents,@time)";

            SqlParameterparam = new SqlParameter("@name",Session["name"].ToString());

            comm.Parameters.Add(param);

            param =newSqlParameter("@contents",cke.Text);

            comm.Parameters.Add(param);

            param =newSqlParameter("@time",DateTime.Now);

            comm.Parameters.Add(param);

            conn.Open();

            comm.ExecuteNonQuery();

            this.GridView1.DataSource= null;

            get();

            comm.Dispose();

            conn.Dispose();

        }

 

        privatevoid get()

        {

            stringstr = "datasource=LENOVO-PC\\SQLEXPRESS;database=MyTest;Integrated Security=true";

            SqlConnectionconn = new SqlConnection(str);

 

            SqlCommandcomm = new SqlCommand();

            comm.Connection = conn;

            comm.CommandText = "fenye";

            comm.CommandType = CommandType.StoredProcedure;

            comm.Parameters.AddWithValue("@pageindex", Convert.ToInt32(ViewState["pageindex"]));

            comm.Parameters.AddWithValue("@pagesize", pagesize);

            SqlDataAdapteradpter = new SqlDataAdapter(comm);

            DataTabledt = new DataTable();

            adpter.Fill(dt);

            this.GridView1.DataSource= dt;

            this.GridView1.DataBind();

            comm.Dispose();

            conn.Dispose();

        }

 

        protectedvoid Button1_Click(objectsender, EventArgs e)

        {

            Response.Redirect("denglu.aspx");

        }

 

        protectedvoid btnno1_Click(objectsender, EventArgs e)

        {

            ViewState["pageindex"]= "1";

            get();

        }

 

        protectedvoid btnlast_Click(objectsender, EventArgs e)

        {

            intpageindex = Convert.ToInt32(ViewState["pageindex"]);

            if(pageindex > 1)

            {

                pageindex--;

            }

            ViewState["pageindex"]= pageindex.ToString();

            get();

        }

 

        protectedvoid btnnext_Click(objectsender, EventArgs e)

        {

            intpageindex = Convert.ToInt32(ViewState["pageindex"]);

            if(pageindex < GetTotalSize())

            {

                pageindex++;

            }

            ViewState["pageindex"]= pageindex.ToString();

            get();

        }

 

        protectedvoid btnmoye_Click(objectsender, EventArgs e)

        {

            ViewState["pageindex"]= GetTotalSize();

            get();

        }

 

        privateint GetTotalSize()

        {

            stringstr = "datasource=LENOVO-PC\\SQLEXPRESS;database=MyTest;Integrated Security=true";

            SqlConnectionconn = new SqlConnection(str);

 

            SqlCommandcomm = new SqlCommand();

            comm.Connection = conn;

           conn.Open();

            comm.CommandText = "select count(*) from liuyanban";

            objectobj = comm.ExecuteScalar();

            if(obj != null)

            {

                inttotal = Convert.ToInt32(obj);

                if(total % pagesize == 0)

                {

                    returntotal / pagesize;

                }

                else

                {

                    returntotal / pagesize + 1;

                }

            }

            comm.Dispose();

            conn.Dispose();

            return0;

        }

    }

}

  存儲過程:

 

USE [MyTest]

GO

/******Object:  StoredProcedure[dbo].[fenye]    Script Date: 03/22/201220:25:10 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

--=============================================

-- Author:    <Author,,Name>

-- Createdate: <Create Date,,>

--Description:   <Description,,>

--=============================================

ALTER PROCEDURE [dbo].[fenye]

    -- Add the parameters for the storedprocedure here

    @pageindex int,

    @pagesize int

AS

BEGIN

    -- SET NOCOUNT ON added to preventextra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNTON;

 

    -- Insertstatements for procedure here

    select name,contents,time from(select ROW_NUMBER() over(order by id)as rownum,*from liuyanban)t

where rownum>(@pageindex-1)*@pagesize and rownum<=@pageindex*@pagesize order by id desc

END

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章