前台文件
<div id="dAdminHeader"><ul><li><a href="AddEditCategory.aspx"><span>New Categoryspan>a>li><li><a href="ManageArticles.aspx"><span>Manage Articlesspan>a>li><li><a href="AddEditArticle.aspx"><span>New Articlespan>a>li>ul> div><ItemTemplate> <tr><td class="ListTitle"><a href='<%# String.Format("AddEditCategory.aspx?categoryid={0}", Eval("CategoryId")) %>'><%# Eval("Title") %>
a>td><td align="center"><a href="<%# String.Format("AddEditCategory.aspx?categoryid={0}", Eval("categoryid")) %>"><img src="../images/edit.gif" alt="" width="16" height="16" class="AdminImg" />
a>td><td align="center"><asp:ImageButton runat="server" ID="btnDeleteCategory" CommandArgument='<%# Eval("CategoryID").ToString() %>'CommandName="Delete" ImageUrl="~/images/delete.gif" AlternateText="Delete" CssClass="AdminImg"OnClientClick="return confirm('Warning: This will delete the Category from the database.');" />td>
tr>
ItemTemplate>
后台文件
1 using System.Collections.Generic; 2 using System.Web.UI.WebControls; 3 using TBHBLL.Articles; 4 using TheBeerHouse.BLL.Articles; 5 using System.Security; 6 using TheBeerHouse.UI; 7 8 partial class Admin_ManageCategories : AdminPage 9 { 10 protected void Page_Load(object sender, System.EventArgs e) 11 { 12 if (!IsPostBack) { 13 if (this.User.Identity.IsAuthenticated && (this.User.IsInRole("Administrators") | 14 this.User.IsInRole("Editors") | this.User.IsInRole("Contributors") | this.User.IsInRole("Posters"))) { 15 BindCategories(); 16 } 17 else { 18 throw new SecurityException("You are not allowed to edit existing articles!"); 19 20 } 21 22 } 23 } 24 25 protected void BindCategories() 26 { 27 28 using (CategoryRepository Categoryrpt = new CategoryRepository()) { 29 30 ListlCategories = Categoryrpt.GetActiveCategories(); 31 lvCategories.DataSource = lCategories; 32 lvCategories.DataBind(); 33 34 SetupListViewPager(lCategories.Count, (DataPager)lvCategories.FindControl("pagerBottom")); 35 36 } 37 } 38 39 protected void lvCategories_ItemDeleting(object sender, System.Web.UI.WebControls.ListViewDeleteEventArgs e) 40 { 41 using (CategoryRepository lCategoryrpt = new CategoryRepository()) { 42 lCategoryrpt.DeleteCategory(int.Parse(lvCategories.DataKeys[e.ItemIndex].Value.ToString())); 43 BindCategories(); 44 } 45 } 46 47 protected void lvCategories_PagePropertiesChanged(object sender, System.EventArgs e) 48 { 49 BindCategories(); 50 } 51 52 }