有缺陷的留言板
来源:互联网 发布:林仕鼎 知乎 编辑:程序博客网 时间:2024/04/30 11:31
页面设置:
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="留¢?言?板ã?.aspx.cs"Inherits="ajax.留¢?言?板ã?"%>
<%@Registerassembly="CKEditor.NET"namespace="CKEditor.NET"tagprefix="CKEditor"%>
<!DOCTYPEhtml PUBLIC "-//W3C//DTDXHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
<styletype="text/css">
body
{
width:960px;
height:900px;
position:relative;
margin:0pxauto;
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>
<formid="form1" runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager>
<asp:UpdatePanelID="UpdatePanel1" runat="server">
<ContentTemplate>
<divid="content">
<divid="liuyan">
<CKEditor:CKEditorControlID="cke" runat="server" Height="202px"></CKEditor:CKEditorControl>
<br/>
<asp:ButtonID="btnpl" runat="server" Text="评¨¤论?"onclick="btnpl_Click"/>
<asp:ButtonID="Button1" runat="server" onclick="Button1_Click"Text="登Ì?陆?"/>
</div>
<divid="contents">
<asp:GridViewID="GridView1" runat="server" AutoGenerateColumns="False"
style="text-align: left;margin-top: 100px;"Width="100%" Height="100%">
<Columns>
<asp:BoundFieldDataField="name" HeaderText="游®?客¨ª"/>
<asp:BoundFieldDataField="contents"HeaderText="内¨²容¨Y"/>
<asp:BoundFieldDataField="time" HeaderText="留¢?言?时º¡À间?"/>
</Columns>
</asp:GridView>
</div>
<asp:ButtonID="btnno1" runat="server" Text="首º¡Á页°3"onclick="btnno1_Click"/>
<asp:ButtonID="btnlast" runat="server" Text="上¦?一°?页°3"onclick="btnlast_Click"/>
<asp:ButtonID="btnnext" runat="server" Text="下?一°?页°3"onclick="btnnext_Click"/>
<asp:ButtonID="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_NULLSON
GO
SET QUOTED_IDENTIFIERON
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,timefrom(selectROW_NUMBER() over(orderby id)asrownum,*fromliuyanban)t
where rownum>(@pageindex-1)*@pagesizeand rownum<=@pageindex*@pagesizeorder by id desc
END
- 有缺陷的留言板
- 实现有管理功能的ASP留言板
- 有缺陷的人能不能成功?
- 有缺陷的人能不能成功?
- autocad输入的列表有缺陷解决方法
- 用ECMAScript 写的轮播图 有缺陷
- 我可是一个有图的留言板咳咳√
- SWT真的有缺陷?SWT的缺陷就是因为不是J2SE一部分
- AccessibilityService有哪些缺陷?
- 图的割边(有缺陷的算法)
- 面向对象设计的一个有缺陷的缓存机制
- 从缺陷中发现长处(有启发的故事)
- 现在好的测试缺陷管理工具都有哪些啊?
- 第一次创业的人通常都有那些能力缺陷
- 第一次创业的人通常都有那些能力缺陷?
- 用命令安装程序,有缺陷的静默安装
- 发现这样得到的心容易有缺陷;
- 最简单的留言板
- C++学习日记day03
- Intent匹配规则以及解析框架深入分析
- C++继承(2)
- UNIX网络编程学习(5)--只支持IPv4的inet_pton和inet_ntop的简化版本
- 解决AJAX中使用UpdatePanel后再用RegisterStartupScript等无法弹出对话框问题
- 有缺陷的留言板
- Vim settings(.vimrc or _vimrc)
- 自定义类如何在ClassWizard中显示
- Html
- POJ 3974 最长回文 Manacher算法
- C++学习日记day04
- 13--软件系统分析与设计
- 29、栈的push、pop序列
- Oracle存储过程介绍及实例