温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:BlogEngine v1.3 多皮肤多语言版源码
当前文件路径:BlogEngine/admin/Pages/Categories.aspx.cs

1Using 12
13
public partial class admin_Pages_Categories : System.Web.UI.Page 14
{ 15
/// <summary> 16
/// Handles the Load event of the Page control. 17
/// </summary> 18
/// <param name="sender">The source of the event.</param> 19
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 20
protected void Page_Load(object sender, EventArgs e) 21
{ 22
if (!Page.IsPostBack) 23
{ 24
BindGrid(); 25
} 26
27
grid.RowEditing += new GridViewEditEventHandler(grid_RowEditing); 28
grid.RowUpdating += new GridViewUpdateEventHandler(grid_RowUpdating); 29
grid.RowCancelingEdit += delegate { Response.Redirect(Request.RawUrl); }; 30
grid.RowDeleting += new GridViewDeleteEventHandler(grid_RowDeleting); 31
btnAdd.Click += new EventHandler(btnAdd_Click); 32
btnAdd.Text = Resources.labels.add + " " + Resources.labels.category.ToLowerInvariant(); 33
valExist.ServerValidate += new ServerValidateEventHandler(valExist_ServerValidate); 34
Page.Title = Resources.labels.categories; 35
} 36
37
/// <summary> 38
/// Handles the ServerValidate event of the valExist control. 39
/// </summary> 40
/// <param name="source">The source of the event.</param> 41
/// <param name="args">The <see cref="System.Web.UI.WebControls.ServerValidateEventArgs"/> instance containing the event data.</param> 42
private void valExist_ServerValidate(object source, ServerValidateEventArgs args) 43
{ 44
args.IsValid = true; 45
46
foreach (Category category in Category.Categories) 47
{ 48
if (category.Title.Equals(txtNewCategory.Text.Trim(), StringComparison.OrdinalIgnoreCase)) 49
args.IsValid = false; 50
} 51
} 52
53
/// <summary> 54
/// Handles the Click event of the btnAdd control. 55
/// </summary> 56
/// <param name="sender">The source of the event.</param> 57
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 58
void btnAdd_Click(object sender, EventArgs e) 59
{ 60
if (Page.IsValid) 61
{ 62
Category cat = new Category(txtNewCategory.Text, txtNewNewDescription.Text); 63
cat.Save(); 64
Response.Redirect(Request.RawUrl, true); 65
} 66
} 67
68
/// <summary> 69
/// Handles the RowDeleting event of the grid control. 70
/// </summary> 71
/// <param name="sender">The source of the event.</param> 72
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewDeleteEventArgs"/> instance containing the event data.</param> 73
void grid_RowDeleting(object sender, GridViewDeleteEventArgs e) 74
{ 75
Guid id = (Guid)grid.DataKeys[e.RowIndex].Value; 76
Category cat = Category.GetCategory(id); 77
78
// Removes all references to the category 79
foreach (Post post in Post.Posts) 80
{ 81
if (post.Categories.Contains(cat)) 82
{ 83
post.Categories.Remove(cat); 84
} 85
} 86
87
cat.Delete(); 88
cat.Save(); 89
Response.Redirect(Request.RawUrl); 90
} 91
92
/// <summary> 93
/// Handles the RowUpdating event of the grid control. 94
/// </summary> 95
/// <param name="sender">The source of the event.</param> 96
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewUpdateEventArgs"/> instance containing the event data.</param> 97
void grid_RowUpdating(object sender, GridViewUpdateEventArgs e) 98
{ 99
Guid id = (Guid)grid.DataKeys[e.RowIndex].Value; 100
TextBox textboxTitle = (TextBox)grid.Rows[e.RowIndex].FindControl("txtTitle"); 101
TextBox textboxDescription = (TextBox)grid.Rows[e.RowIndex].FindControl("txtDescription"); 102
Category cat = Category.GetCategory(id); 103
cat.Title = textboxTitle.Text; 104
cat.Description = textboxDescription.Text; 105
cat.Save(); 106
107
Response.Redirect(Request.RawUrl); 108
} 109
110
/// <summary> 111
/// Handles the RowEditing event of the grid control. 112
/// </summary> 113
/// <param name="sender">The source of the event.</param> 114
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewEditEventArgs"/> instance containing the event data.</param> 115
void grid_RowEditing(object sender, GridViewEditEventArgs e) 116
{ 117
grid.EditIndex = e.NewEditIndex; 118
BindGrid(); 119
} 120
121
/// <summary> 122
/// Binds the grid with all the categories. 123
/// </summary> 124
private void BindGrid() 125
{ 126
grid.DataKeyNames = new string[] { "Id" }; 127
grid.DataSource = Category.Categories; 128
grid.DataBind(); 129
} 130
131
} 132





