温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:超酷的Asp.net2.0留言板
当前文件:
VeryCoolGuest/Default.aspx.cs[4K,2009-6-12 11:57:57],打开代码结构图
VeryCoolGuest/Default.aspx.cs[4K,2009-6-12 11:57:57],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Web; 5
using System.Web.Security; 6
using System.Web.UI; 7
using System.Web.UI.WebControls; 8
using System.Web.UI.WebControls.WebParts; 9
using System.Web.UI.HtmlControls; 10
using System.Data.SqlClient; 11
//该源码下载自www.51aspx.com(51aspx.com) 12
13
public partial class _Default : System.Web.UI.Page 14
{ 15
string curPage; 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
if (!IsPostBack) 19
{ 20
this.lblPageCur.Text = "1";//不能放到dataGridBind()后面,不然lblPageCur.Text没有被初始化,出错 21
dataGridBind(); 22
} 23
} 24
public void dataGridBind() 25
{ 26
curPage =this.lblPageCur.Text; 27
SqlConnection conn = DB.createCon(); 28
SqlCommand cmd = new SqlCommand(); 29
cmd.CommandText = "select * from guest order by postTime desc"; 30
cmd.Connection = conn; 31
SqlDataAdapter sda = new SqlDataAdapter(); 32
sda.SelectCommand = cmd; 33
DataSet ds = new DataSet(); 34
sda.Fill(ds, "guest"); 35
PagedDataSource pds = new PagedDataSource(); 36
pds.AllowPaging = true; 37
pds.PageSize = 3; 38
pds.DataSource = ds.Tables["guest"].DefaultView; 39
pds.CurrentPageIndex = Convert.ToInt32(curPage) - 1; 40
this.lblPageTotal.Text = pds.PageCount.ToString(); 41
this.Button1.Enabled=true; 42
this.Button2.Enabled=true; 43
if (curPage == "1") 44
{ 45
this.Button1.Enabled = false; 46
} 47
if (curPage == pds.PageCount.ToString()) 48
{ 49
this.Button2.Enabled = false; 50
} 51
this.DataList1.DataSource = pds; 52
this.DataList1.DataBind(); 53
54
cmd.CommandText = "select count(*) from guest"; 55
this.lblMesTotal.Text = Convert.ToString(cmd.ExecuteScalar()); 56
57
int a = pds.PageCount; 58
for(int i=1;i<=a;i++) 59
{ 60
this.DropDownList1.Items.Add(i.ToString()); 61
} 62
} 63
64
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) 65
{ 66
LinkButton dele=(LinkButton)(e.Item.FindControl("lbtnDelete")); 67
if (dele != null) 68
{ 69
dele.Attributes.Add("onclick","return confirm('确定删除吗?')"); 70
} 71
} 72
73
protected void lbtnDelete_Command(object sender, CommandEventArgs e) 74
{ 75
if(Session["admin"]!=null) 76
{ 77
//string userID = Request.QueryString["userID"]; //不好传送,试了N遍 78
string userID = e.CommandArgument.ToString(); 79
SqlCommand cmd = new SqlCommand(); 80
cmd.Connection = DB.createCon(); 81
cmd.CommandText = "delete from guest where ID='"+userID+"'"; 82
if (cmd.ExecuteNonQuery() > 0) 83
{ 84
Response.Write("<script>alert('删除成功!');window.location=window.location;</script>"); 85
} 86
else 87
{ 88
Response.Write("<script>alert('删除失败!');window.location=window.location;</script>"); 89
} 90
} 91
else 92
{ 93
Response.Write("<script>alert('对不起,只有管理员才允许删除留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>"); 94
} 95
} 96
97
protected void lbtnReply_Command(object sender, CommandEventArgs e) 98
{ 99
if (Session["admin"] != null) 100
{ 101
//string userID = Request.QueryString["userID"]; //这样通过页面来传送,不用e.CommandArgument,会出错,试了N遍 102
string userID = e.CommandArgument.ToString(); 103
Response.Redirect("reply.aspx?userID="+userID+""); 104
} 105
else 106
{ 107
Response.Write("<script>alert('对不起,只有管理员才允许回复留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>"); 108
} 109
} 110
protected void Button1_Click(object sender, EventArgs e) 111
{ 112
this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text)-1); 113
dataGridBind(); 114
} 115
protected void Button2_Click(object sender, EventArgs e) 116
{ 117
this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text) + 1); 118
dataGridBind(); 119
} 120
protected void Button3_Click(object sender, EventArgs e) 121
{ 122
this.lblPageCur.Text = "1"; 123
dataGridBind(); 124
} 125
protected void Button4_Click(object sender, EventArgs e) 126
{ 127
this.lblPageCur.Text = this.lblPageTotal.Text; 128
dataGridBind(); 129
} 130
protected void Button5_Click(object sender, EventArgs e) 131
{ 132
if (!IsPostBack) 133
{ 134
this.lblPageCur.Text = this.DropDownList1.SelectedValue; 135
dataGridBind(); 136
} 137
} 138
} 139






}
}