分类管理模块-修改新闻分类(简单版本)

设计界面如下:

HTML代码如下:

 1 <body>
 2 <form id="form1" runat="server">
 3     <div>
 4     
 5         <table cellpadding="0" cellspacing="0" style="width: 100%">
 6             <tr>
 7                 <td style="width: 211px">
 8                     修改新闻分类</td>
 9                 <td colspan="2">
10                     &nbsp;</td>
11             </tr>
12             <tr>
13                 <td rowspan="5" style="width: 211px">
14                     <asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows" 
15                         onselectednodechanged="TreeView1_SelectedNodeChanged">
16                         <ParentNodeStyle Font-Bold="False" />
17                         <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
18                         <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" 
19                             HorizontalPadding="0px" VerticalPadding="0px" />
20                         <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" 
21                             HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
22                     </asp:TreeView>
23                 </td>
24                 <td colspan="2" style="text-align: center">
25                     <asp:Label ID="lblMessage" runat="server"></asp:Label>
26                 </td>
27             </tr>
28             <tr>
29                 <td style="width: 166px; text-align: center">
30                     ID</td>
31                 <td>
32                     <asp:TextBox ID="txtClassID" runat="server"></asp:TextBox>
33                 </td>
34             </tr>
35             <tr>
36                 <td style="width: 166px; text-align: center">
37                     分类名称:</td>
38                 <td>
39                     <asp:TextBox ID="txtClassName" runat="server"></asp:TextBox>
40                 </td>
41             </tr>
42             <tr>
43                 <td style="width: 166px; text-align: center">
44                     是否有子类:</td>
45                 <td>
46                     <asp:RadioButtonList ID="rblLastNode" runat="server" 
47                         RepeatDirection="Horizontal">
48                         <asp:ListItem Selected="True" Value="1"></asp:ListItem>
49                         <asp:ListItem Value="0"></asp:ListItem>
50                     </asp:RadioButtonList>
51                 </td>
52             </tr>
53             <tr>
54                 <td style="width: 166px; height: 117px; text-align: center">
55                     备注</td>
56                 <td style="height: 117px">
57                     <asp:TextBox ID="txtExample" runat="server" Height="111px" TextMode="MultiLine" 
58                         Width="241px"></asp:TextBox>
59                 </td>
60             </tr>
61             <tr>
62                 <td style="width: 211px">
63                     &nbsp;</td>
64                 <td style="width: 166px">
65                     &nbsp;</td>
66                 <td>
67                     <asp:Button ID="btnUpdate" runat="server" onclick="btnUpdate_Click" 
68                         Text="提交修改" />
69                 </td>
70             </tr>
71         </table>
72     
73     </div>
74     </form>
75 </body>

CS代码如下:

 1 public partial class Admin_Admin_ClassEdit : System.Web.UI.Page
 2 {
 3     protected void Page_Load(object sender, EventArgs e)
 4     {   this.TreeView1.Nodes.Clear();
 5     BindTree(this.TreeView1.Nodes, 0);
 6     }
 7     private void BindTree(TreeNodeCollection treecol, int parentID)
 8     {
 9         CategoryBLL catsystem = new CategoryBLL();
10         List<Category> cateList = catsystem.GetClassDataID(parentID);
11         foreach (Category cateData in cateList)
12         {
13             TreeNode node = new TreeNode();
14             node.Text = cateData.ClassName + "(" + cateData.Child + ")";
15             node.Value = cateData.ClassId.ToString();
16             treecol.Add(node);
17             BindTree(node.ChildNodes, int.Parse(node.Value));
18         }
19 
20     }
21     protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
22     {
23         int id = int.Parse(this.TreeView1.SelectedNode.Value);
24         Category classdata = new Category();
25         classdata = (new CategoryBLL()).GetclassID(id);
26         txtClassID.Text = classdata.ClassId.ToString();
27         txtClassName.Text = classdata.ClassName;
28         txtExample.Text = classdata.Example;
29         //rblLastNode.SelectedItem.Value = classdata.LastNode.ToString();
30     }
31     protected void btnUpdate_Click(object sender, EventArgs e)
32     {
33         Category cateData = new Category();
34         cateData.ClassId = int.Parse(txtClassID.Text.Trim());
35         cateData.ClassName = txtClassName.Text.Trim();
36         cateData.LastNode = int.Parse(this.rblLastNode.SelectedValue.ToString());
37         cateData.Example = this.txtExample.Text.Trim();
38         CategoryBLL catesystem = new CategoryBLL();
39         catesystem.UpdateClass(cateData);
40         this.ClientScript.RegisterStartupScript(this.GetType(), "succeed", "<script>alert('修改成功')</script>");
41         this.TreeView1.Nodes.Clear();
42         BindTree(this.TreeView1.Nodes, 0);
43         Response.Redirect("Admin_ClassEdit.aspx");
44     }
45 }

BLL类:

 1 /// <summary>
 2     /// 更新分类信息
 3     /// </summary>
 4     /// <param name="cateData"></param>
 5     /// <returns></returns>
 6     public bool UpdateClass(Category cateData)
 7     {
 8         CategoryDAL catesystem = new CategoryDAL();
 9         return catesystem.Updateclass(cateData);
10     }

DAL类:

 1 /// <summary>
 2     /// 修改分类信息
 3     /// </summary>
 4     /// <param name="classData"></param>
 5     /// <returns></returns>
 6     public bool Updateclass(Category classData)
 7     {
 8         DataClassesDataContext db = new DataClassesDataContext();
 9         bool result = false;
10         try
11         {
12             Category classresult = db.Category.Where(c => c.ClassId == classData.ClassId).First();
13             classresult.ClassName = classData.ClassName;
14             db.SubmitChanges();
15             result = true;
16         }
17         catch
18         { }
19         return result;
20     }
posted @ 2012-06-08 22:33  阿杜008  阅读(504)  评论(0)    收藏  举报