您的位置:首页 > 其它

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

2012-06-08 22:33 309 查看
设计界面如下:



HTML代码如下:

<body>
<form id="form1" runat="server">
<div>

<table cellpadding="0" cellspacing="0" style="width: 100%">
<tr>
<td style="width: 211px">
修改新闻分类</td>
<td colspan="2">
 </td>
</tr>
<tr>
<td rowspan="5" style="width: 211px">
<asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows"
onselectednodechanged="TreeView1_SelectedNodeChanged">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"
HorizontalPadding="0px" VerticalPadding="0px" />
<NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black"
HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
</td>
<td colspan="2" style="text-align: center">
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td style="width: 166px; text-align: center">
ID</td>
<td>
<asp:TextBox ID="txtClassID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 166px; text-align: center">
分类名称:</td>
<td>
<asp:TextBox ID="txtClassName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 166px; text-align: center">
是否有子类:</td>
<td>
<asp:RadioButtonList ID="rblLastNode" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Value="1">是</asp:ListItem>
<asp:ListItem Value="0">否</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td style="width: 166px; height: 117px; text-align: center">
备注</td>
<td style="height: 117px">
<asp:TextBox ID="txtExample" runat="server" Height="111px" TextMode="MultiLine"
Width="241px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 211px">
 </td>
<td style="width: 166px">
 </td>
<td>
<asp:Button ID="btnUpdate" runat="server" onclick="btnUpdate_Click"
Text="提交修改" />
</td>
</tr>
</table>

</div>
</form>
</body>


CS代码如下:

public partial class Admin_Admin_ClassEdit : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{   this.TreeView1.Nodes.Clear();
BindTree(this.TreeView1.Nodes, 0);
}
private void BindTree(TreeNodeCollection treecol, int parentID)
{
CategoryBLL catsystem = new CategoryBLL();
List<Category> cateList = catsystem.GetClassDataID(parentID);
foreach (Category cateData in cateList)
{
TreeNode node = new TreeNode();
node.Text = cateData.ClassName + "(" + cateData.Child + ")";
node.Value = cateData.ClassId.ToString();
treecol.Add(node);
BindTree(node.ChildNodes, int.Parse(node.Value));
}

}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
int id = int.Parse(this.TreeView1.SelectedNode.Value);
Category classdata = new Category();
classdata = (new CategoryBLL()).GetclassID(id);
txtClassID.Text = classdata.ClassId.ToString();
txtClassName.Text = classdata.ClassName;
txtExample.Text = classdata.Example;
//rblLastNode.SelectedItem.Value = classdata.LastNode.ToString();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
Category cateData = new Category();
cateData.ClassId = int.Parse(txtClassID.Text.Trim());
cateData.ClassName = txtClassName.Text.Trim();
cateData.LastNode = int.Parse(this.rblLastNode.SelectedValue.ToString());
cateData.Example = this.txtExample.Text.Trim();
CategoryBLL catesystem = new CategoryBLL();
catesystem.UpdateClass(cateData);
this.ClientScript.RegisterStartupScript(this.GetType(), "succeed", "<script>alert('修改成功')</script>");
this.TreeView1.Nodes.Clear();
BindTree(this.TreeView1.Nodes, 0);
Response.Redirect("Admin_ClassEdit.aspx");
}
}


BLL类:

/// <summary>
/// 更新分类信息
/// </summary>
/// <param name="cateData"></param>
/// <returns></returns>
public bool UpdateClass(Category cateData)
{
CategoryDAL catesystem = new CategoryDAL();
return catesystem.Updateclass(cateData);
}


DAL类:

/// <summary>
/// 修改分类信息
/// </summary>
/// <param name="classData"></param>
/// <returns></returns>
public bool Updateclass(Category classData)
{
DataClassesDataContext db = new DataClassesDataContext();
bool result = false;
try
{
Category classresult = db.Category.Where(c => c.ClassId == classData.ClassId).First();
classresult.ClassName = classData.ClassName;
db.SubmitChanges();
result = true;
}
catch
{ }
return result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: