-
Notifications
You must be signed in to change notification settings - Fork 2
/
ShowNewsInformation.aspx.cs
executable file
·105 lines (102 loc) · 3.31 KB
/
ShowNewsInformation.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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.Linq;
using System.Data.SqlClient;
// 下载于www.51aspx.com
public partial class ShowNewsInformation : System.Web.UI.Page
{
SqlData da = new SqlData();
protected void Page_Load(object sender, EventArgs e)
{
Bind();
}
protected void Bind()
{
int count = Convert.ToInt32(Request.QueryString["id"]);
switch (count)
{
case 1:
Label4 .Text = "时事新闻";
break;
case 2:
Label4.Text = "环球经济";
break;
case 3:
Label4.Text = "军事世界";
break;
case 4:
Label4.Text = "科学技术";
break;
case 5:
Label4.Text = "生活理财";
break;
case 6:
Label4 .Text = "社会百态";
break;
case 7:
Label4.Text = "世界体育";
break;
case 8:
Label4 .Text = "娱乐综艺";
break;
}
int currentPage = Convert.ToInt32(this.currentPage.Text);
PagedDataSource pds = new PagedDataSource();
string sqlstring = "select * from tb_News where Categories='" + Label4 .Text .Trim () + "' order by issueDate desc";
DataSet ds = da.datesetExecute(sqlstring, "tbNews");
pds.DataSource = ds.Tables["tbNews"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
pds.CurrentPageIndex = currentPage - 1;
this.firstPage.Enabled = true;
this.frontPage.Enabled = true;
this.nextPage.Enabled = true;
this.lastPage.Enabled = true;
if (currentPage == 1)
{
this.firstPage.Enabled = false;
this.frontPage.Enabled = false;
}
if (currentPage == pds.Count)
{
this.nextPage.Enabled = false;
this.lastPage.Enabled = false;
}
this.totalPage.Text = Convert.ToString(pds.PageCount);
this.dlstNews.DataSource = pds;
this.dlstNews.DataKeyField = "id";
this.dlstNews.DataBind();
}
protected void firstPage_Click(object sender, EventArgs e)
{
this.currentPage.Text = "1";
this.Bind();
}
protected void frontPage_Click(object sender, EventArgs e)
{
this.currentPage.Text = Convert.ToString(Convert.ToInt32(this.currentPage.Text) - 1);
this.Bind();
}
protected void nextPage_Click(object sender, EventArgs e)
{
this.currentPage.Text = Convert.ToString(Convert.ToInt32(this.currentPage.Text) + 1);
}
protected void lastPage_Click(object sender, EventArgs e)
{
this.currentPage.Text = Convert.ToString(Convert.ToInt32(this.totalPage.Text));
this.Bind();
}
protected void ldNewsSort_ItemCommand(object source, DataListCommandEventArgs e)
{
int id = Convert.ToInt32(dlstNews.DataKeys[e.Item.ItemIndex].ToString());
Response.Redirect("NewsDetail.aspx?id=" + id + "");
}
}