asp.net treeview数据库绑定 (节点添加 删除 修改)
来源:互联网 发布:c语言flag是什么意思 编辑:程序博客网 时间:2024/05/16 01:09
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddKind.aspx.cs" Inherits="MyAdmin_AddKind" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.style1
{
width: 800px;
}
.style2
{
width: 204px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="0" cellspacing="0" class="style1">
<tr>
<td>
</td>
<td class="style2">
<asp:TreeView ID="tvKind" runat="server"
onselectednodechanged="tvKind_SelectedNodeChanged" Width="128px">
</asp:TreeView>
</td>
<td>
父节点:<asp:TextBox ID="txtParent" runat="server" Width="223px"></asp:TextBox>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
子节点:<asp:TextBox ID="txtChild" runat="server" Width="221px"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click" Text="添加" />
<asp:Button ID="btnUpdate" runat="server" onclick="btnUpdate_Click" Text="修改" />
<asp:Button ID="btnDelete" runat="server" onclick="btnDelete_Click" Text="删除" />
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
。。。。。。。。。。。。。。。。。。。。
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
public partial class MyAdmin_AddKind : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TVGenNode();
}
private void TVGenNode()
{
this.tvKind.Nodes.Clear();
TreeNode tnGen = new TreeNode();
tnGen.Text = "新闻类别管理";
tnGen.Value = "F000";
tnGen.Expanded = true;
tvKind.Nodes.Add(tnGen);
TVParentNode(tnGen);
}
public void TVParentNode(TreeNode tnParent)
{
string sqlStr = System.Configuration.ConfigurationManager.ConnectionStrings["ZYNewsConnStr"].ConnectionString;
SqlConnection conn = new SqlConnection(sqlStr);
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from mykind where parentid='F000'", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
TreeNode parentNode = new TreeNode();
parentNode.Text = (string)dr["kindName"];
parentNode.Value = (string)dr["smallId"];
parentNode.Expanded = true;
tnParent.ChildNodes.Add(parentNode);
TVChildNode(parentNode);
}
}
public void TVChildNode(TreeNode tnParent)
{
string sqlStr = System.Configuration.ConfigurationManager.ConnectionStrings["ZYNewsConnStr"].ConnectionString;
SqlConnection conn = new SqlConnection(sqlStr);
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from mykind where parentid='" + tnParent.Value + "'", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
TreeNode parentNode = new TreeNode();
parentNode.Text = (string)dr["kindName"];
parentNode.Value = (string)dr["smallId"];
parentNode.Expanded =true;
tnParent.ChildNodes.Add(parentNode);
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
string sqlStr = System.Configuration.ConfigurationManager.ConnectionStrings["ZYNewsConnStr"].ConnectionString;
SqlConnection conn = new SqlConnection(sqlStr);
conn.Open();
SqlCommand comm = new SqlCommand("delete from mykind where smallId='"+Label1.Text+"'",conn);
comm.ExecuteNonQuery();
TVGenNode();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
string sqlStr = System.Configuration.ConfigurationManager.ConnectionStrings["ZYNewsConnStr"].ConnectionString;
SqlConnection conn = new SqlConnection(sqlStr);
conn.Open();
SqlCommand comm = new SqlCommand("update mykind set kindname='"+txtParent.Text+"' where smallId='" + Label1.Text + "'", conn);
comm.ExecuteNonQuery();
TVGenNode();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
string sqlStr = System.Configuration.ConfigurationManager.ConnectionStrings["ZYNewsConnStr"].ConnectionString;
SqlConnection conn = new SqlConnection(sqlStr);
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select smallId from mykind",conn);
DataSet ds = new DataSet();
sda.Fill(ds);
string smallID = "";
if (ds.Tables[0].Rows.Count == 0)
smallID = "F000";
else
smallID="F"+(Convert.ToInt32(ds.Tables[0].Rows[ds.Tables[0].Rows.Count-1][0].ToString().Substring(1,3))+1);
SqlCommand comm = new SqlCommand("insert into mykind(smallId,kindname,parentid) values('"+smallID+"','"+txtChild.Text+"','"+Label1.Text+"') ", conn);
comm.ExecuteNonQuery();
TVGenNode();
}
protected void tvKind_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNode treenode = this.tvKind.SelectedNode;
txtParent.Text = treenode.Text;
Label1.Text = treenode.Value;
}
}
- asp.net treeview数据库绑定 (节点添加 删除 修改)
- asp.net treeview数据库绑定 (节点添加 删除 修改)
- ASP.NET - 如何:添加或删除 TreeView 节点元素
- ASP.NET TreeView Web Control 添加,删除,修改
- 浅析动态添加、删除、修改TreeView节点
- asp.net treeview绑定数据库,并取节点和节点的内容
- asp.net TreeView绑定数据库(测试成功)
- ASP.NET TreeView动态绑定数据库显示
- ASP.net 中关于控件Treeview的操作------ 节点查找、删除和添加
- asp.net 绑定TreeView
- asp treeview绑定数据库
- TreeView树型菜单添加,修改,删除,绑定DropDownList功能
- asp.net(VB)操作Access数据库(链接/添加/修改/删除)
- asp.net(VB)操作Access数据库(链接/添加/修改/删除)
- TreeView 添加,删除,更改 节点
- Asp.Net C#程序代码动态添加TreeView节点
- asp.net treeview控件无刷新选择和删除节点(使用jquery)
- asp.net treeview控件无刷新选择和删除节点(使用jquery)
- 打开对话框同时选择多个文件+往ListBox添加项
- 态度
- flyinghearts《编程之美》读书笔记连载(18)
- 学生大本营,是一个学习的好平台。
- 黯夜伤
- asp.net treeview数据库绑定 (节点添加 删除 修改)
- 楼下的我
- asp.net treeview数据库绑定 (节点添加 删除 修改)
- 年华似水
- 动态和静态IP地址引起的VPN问题
- 测试设计题(华为)1
- 测试设计题(华为)2
- 一道有趣的问题——关于自加运算的
- 测试