温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:太糊留言板(VS2008+SQL2005)
当前文件:
TaiHuMessage/ShowMes.ascx.cs,打开代码结构图
TaiHuMessage/ShowMes.ascx.cs,打开代码结构图1using System; 2
using System.Collections; 3
using System.Configuration; 4
using System.Data; 5
using System.Linq; 6
using System.Web; 7
using System.Web.Security; 8
using System.Web.UI; 9
using System.Web.UI.HtmlControls; 10
using System.Web.UI.WebControls; 11
using System.Web.UI.WebControls.WebParts; 12
using System.Xml.Linq; 13
using System.Data.SqlClient; 14
15
public partial class ShowMes : System.Web.UI.UserControl 16
{ 17
DB DBManage = new DB(); 18
string curpage; 19
protected void Page_Load(object sender, EventArgs e) 20
{ 21
if(!IsPostBack ) 22
23
BindData(); 24
} 25
public void BindData() 26
{ 27
this.Button1.Enabled = true ; 28
this.Button2.Enabled = true ; 29
this.Button3.Enabled = true ; 30
this.Button4.Enabled = true ; 31
SqlDataAdapter sda = new SqlDataAdapter(); 32
sda.SelectCommand = new SqlCommand("select name,content,time from mes order by id DESC", DBManage.GetConnection()); 33
DataSet ds = new DataSet(); 34
sda.Fill(ds ,"dsmes"); 35
PagedDataSource ps = new PagedDataSource(); 36
ps.AllowPaging = true; 37
ps.DataSource = ds.Tables["dsmes"].DefaultView; 38
ps.PageSize = 5; 39
curpage = this.Label1.Text; 40
ps.CurrentPageIndex = Convert.ToInt32(curpage) - 1; 41
42
43
44
this.DataList1 .DataSource = ps; 45
this.DataList1.DataBind(); 46
DBManage.pagetotal = ps.PageCount; 47
this.Label2.Text ="共"+Convert .ToString( DBManage.pagetotal)+"页"; 48
this.temp.Text =Convert.ToString ( ps.PageCount); 49
if (Convert.ToInt32(curpage) == 1) 50
{ 51
52
this.Button1.Enabled = false; 53
this.Button2.Enabled = false; 54
} 55
if (Convert.ToInt32(curpage) == ps.PageCount) 56
{ 57
58
this.Button3.Enabled = false; 59
this.Button4.Enabled = false; 60
} 61
//for (int i = 1; i <= ps.PageCount; i++) 62
//{ 63
64
// this.DropDownList1.Items.Add("第" + i + "页"); 65
//} 66
if (!IsPostBack) 67
for (int i = 1; i <= ps.PageCount; i++) 68
{ 69
70
this.DropDownList1.Items.Add("第" + i + "页"); 71
} 72
73
DBManage.CloseConnection(); 74
} 75
76
protected void Button1_Click(object sender, EventArgs e) 77
{ 78
this.Label1.Text = "1"; 79
this.DropDownList1.SelectedIndex = Convert.ToInt32(this.Label1.Text); 80
BindData(); 81
82
} 83
protected void Button2_Click(object sender, EventArgs e) 84
{ 85
this.Label1.Text =Convert .ToString ( Convert .ToInt32 ( this.Label1.Text) - 1); 86
this.DropDownList1.SelectedIndex = Convert.ToInt32(this.Label1.Text); 87
BindData(); 88
} 89
protected void Button3_Click(object sender, EventArgs e) 90
{ 91
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) + 1); 92
BindData(); 93
} 94
protected void Button4_Click(object sender, EventArgs e) 95
{ 96
this.Label1.Text = this.temp.Text; 97
98
BindData(); 99
} 100
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 101
{ 102
this.Label1.Text =Convert .ToString ( Convert .ToInt32 ( this.DropDownList1.SelectedIndex)+1); 103
BindData(); 104
} 105
} 106




DB DBManage 
}
}