温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:WebQuest发布系统源码及文档
当前文件:
WebQuest/Admin/admin_subjects.aspx.cs,打开代码结构图
WebQuest/Admin/admin_subjects.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using WebQuest; 12
public partial class Admin_admin_subjects : System.Web.UI.Page 13
{ 14
protected void Page_Load(object sender, EventArgs e) 15
{ 16
if (!IsPostBack) 17
{ 18
this.GridView1.Attributes.Add("SortExpression", "subjectid"); 19
this.GridView1.Attributes.Add("SortDirection", "desc"); 20
BindSubject(); 21
} 22
23
} 24
25
private void BindSubject() 26
{ 27
string SortDirection = this.GridView1.Attributes["SortDirection"].ToString(); 28
string SortExpression = this.GridView1.Attributes["SortExpression"].ToString(); 29
30
31
Subjects myObj = new Subjects(); myObj.Retrieve().Tables[0].DefaultView.Sort = string.Format("{0} {1}", SortExpression, SortDirection); 32
GridView1.DataSource = myObj.Retrieve(); 33
GridView1.DataBind(); 34
} 35
protected void btnDel_Click(object sender, EventArgs e) 36
{ 37
38
Subjects myObj = new Subjects(); 39
40
foreach (GridViewRow row in GridView1.Rows) 41
{ 42
CheckBox mychk = null; 43
mychk = (CheckBox)row.FindControl("chk"); 44
if (mychk.Checked) 45
{ 46
myObj.SubjectId = int.Parse(GridView1.DataKeys[row.DataItemIndex][0].ToString()); 47
myObj.Delete(); 48
} 49
50
} 51
BindSubject(); 52
53
} 54
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 55
{ 56
GridView1.PageIndex = e.NewPageIndex; 57
BindSubject(); 58
} 59
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 60
{ 61
switch (e.CommandName) 62
{ 63
case "sEdit": Response.Redirect("admin_subjects_edit.aspx?id=" + e.CommandArgument.ToString()); break; 64
65
} 66
67
} 68
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) 69
{ 70
if (e.SortExpression != "") 71
{ 72
if (GridView1.PageCount > 0) 73
{ 74
//设定排序方向 75
string SortDirection = "desc"; 76
SortDirection = (this.GridView1.Attributes["SortDirection"].ToString() == SortDirection ? "DESC" : "ASC"); 77
this.GridView1.Attributes["SortExpression"] = e.SortExpression; 78
this.GridView1.Attributes["SortDirection"] = SortDirection; 79
//重新绑定数据 80
BindSubject(); 81
} 82
} 83
84
85
86
87
88
} 89
} 90





}
}