问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

急asp.net TreeView 动态数据绑定

发布网友 发布时间:2022-04-27 12:51

我来回答

2个回答

热心网友 时间:2022-04-27 14:21

给你个例子,照着改改就可以用的
#region 多级别树形导航的处理,绑定第一层
private void PopulateCategories(string strTableName)
{
this.TVMenu.Nodes.Clear();
try
{
string strSQL = "select * from " + strTableName + " where SYS_FLD_CLASS_GRADE = 1";

KBaseServerDAL kal = new KBaseServerDAL();
RecordSet rs = kal.GetDataSetBySQL(strSQL);

if (rs != null && rs.GetCount() > 0)
{
for (int i = 0; i < rs.GetCount(); i++)
{
//string strField = rs.GetValue("SYS_FLD_CLASS_NAME");
TreeNode NewNode = new TreeNode("<a href = " + this.TextBox_Page.Text + "?sysCode=" + rs.GetValue("SYS_FLD_CLASS_NAME").ToString() + ">" + rs.GetValue("SYS_FLD_CLASS_NAME").ToString() + "</a>", "" + rs.GetValue("SYS_FLD_SYS_CODE").ToString() + "," + rs.GetValue("SYS_FLD_CLASS_GRADE").ToString() + "");
NewNode.PopulateOnDemand = true;

this.TVMenu.Nodes.Add(NewNode);
NewNode.CollapseAll();
rs.MoveNext();
}
}

kal.DisconnectServer();
}
catch
{
this.Label_Text.Text = "数据库连接有误,请检查配置。";
}
}
#endregion

#region 多级别树形导航的处理,单击树节点时的处理函数
protected void TVMenu_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
try
{
//防止重复填充节点
if (e.Node.ChildNodes.Count > 0)
return;

string[] str = e.Node.Value.Split(',');
string strSysCode = str[0].ToString();
string strGrade = "";

strGrade = Convert.ToString((Convert.ToInt32(str[1]) + 1));

string strSQL = "select * from " + this.TextBox6.Text.Trim() + " where SYS_FLD_CLASS_GRADE = " + strGrade + " and SYS_FLD_SYS_CODE = '" + strSysCode + "?'";

KBaseServerDAL kal = new KBaseServerDAL();
RecordSet rs = kal.GetDataSetBySQL(strSQL);

if (rs != null && rs.GetCount() > 0)
{
for (int i = 0; i < rs.GetCount(); i++)
{
string strField = rs.GetValue("SYS_FLD_CLASS_NAME");
TreeNode NewNode = new TreeNode("<a href = " + this.TextBox_Page.Text + "?sysCode=" + rs.GetValue("SYS_FLD_CLASS_NAME").ToString() + ">" + rs.GetValue("SYS_FLD_CLASS_NAME").ToString() + "</a>", "" + rs.GetValue("SYS_FLD_SYS_CODE").ToString() + "," + rs.GetValue("SYS_FLD_CLASS_GRADE").ToString() + "");
NewNode.PopulateOnDemand = true;

e.Node.ChildNodes.Add(NewNode);
NewNode.CollapseAll();
rs.MoveNext();
}
}

kal.DisconnectServer();
}
catch
{
this.Label_Text.Text = "数据库连接有误,请检查配置。";
}
}
#endregion

热心网友 时间:2022-04-27 15:39

<script language="javascript" type="text/javascript">
<!--
function TreeView_ToggleNode(data, index, node, lineType, children)
{
var img = node.childNodes[0];
var newExpandState;
try {
//***折叠兄弟节点(Collapse Brothers)-----
CollapseBrothers(data,children);
//---------------------------------------

if (children.style.display == "none")
{
children.style.display = "block";
newExpandState = "e";
if ((typeof(img) != "undefined") && (img != null))
{
if (lineType == "l")
{
img.src = data.images[15];
}
else if (lineType == "t")
{
img.src = data.images[12];
}
else if (lineType == "-")
{
img.src = data.images[18];
}
else
{
img.src = data.images[5];
}
img.alt = data.collapseToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));
}
}
else
{
children.style.display = "none";
newExpandState = "c";
if ((typeof(img) != "undefined") && (img != null))
{
if (lineType == "l")
{
img.src = data.images[14];
}
else if (lineType == "t")
{
img.src = data.images[11];
}
else if (lineType == "-")
{
img.src = data.images[17];
}
else
{
img.src = data.images[4];
}
img.alt = data.expandToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));
}
}
}
catch(e) {}
data.expandState.value = data.expandState.value.substring(0, index) + newExpandState + data.expandState.value.slice(index + 1);
}

//折叠兄弟节点(Collapse Brothers)
function CollapseBrothers(data,childContainer)
{
var parent = childContainer.parentNode;
for(i=0; i< parent.childNodes.length; i++)
{
if(parent.childNodes[i].tagName.toLowerCase() =="div")
{
if(parent.childNodes[i].id != childContainer.id)
{
parent.childNodes[i].style.display = "none"
}
}
else if(parent.childNodes[i].tagName.toLowerCase() =="table")
{
var treeLinks = parent.childNodes[i].getElementsByTagName("a");
if(treeLinks.length > 2)
{
var j=0;
if(treeLinks[j].firstChild.tagName)
{
if(treeLinks[j].firstChild.tagName.toLowerCase() == "img")
{
var img = treeLinks[j].firstChild;
if(i==0)
img.src = data.images[8];
else if(i==parent.childNodes.length-2)
img.src = data.images[14];
else
img.src = data.images[11];
}
}
}
}
}
}
-->
</script>
<asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" ShowLines="True">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="maroon" />
<RootNodeStyle Font-Underline="True" />
<LeafNodeStyle ForeColor="#404000" />
<NodeStyle Font-Names="Verdana" Font-Size="8pt" Font-Underline="True" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
<SelectedNodeStyle BackColor="LightYellow" Font-Bold="False" Font-Underline="True" ForeColor="Green" HorizontalPadding="0px" NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>

protected void bind_trade(string l0, string l1)
{
myConn = new conn();
string L0Sql = "select L0,material from inv_master where L1='0' and L2='0' and isvisible='Y' order by L0";
SqlDataAdapter L0Da = new SqlDataAdapter(L0Sql, myConn.con);
DataSet L0Ds = new DataSet();
L0Da.Fill(L0Ds);
for (int i = 0; i < L0Ds.Tables[0].Rows.Count; i++)
{
DataRowView L0drv = L0Ds.Tables[0].DefaultView[i];
TreeNode childNode = new TreeNode();
childNode.Text = L0drv[1].ToString().Trim();
childNode.Value = L0drv[0].ToString().Trim();
childNode.Expanded = (L0drv[0].ToString().Trim() == l0) ? true : false;
childNode.SelectAction = TreeNodeSelectAction.Expand;
TreeView1.Nodes.Add(childNode);
string L1Sql = "select L1,material,inv_code from inv_master where L0='" + L0drv[0].ToString().Trim() + "' and L2='0' and L1<>'0' and isvisible='Y' order by L1";
SqlDataAdapter L1Da = new SqlDataAdapter(L1Sql, myConn.con);
DataSet L1Ds = new DataSet();
L1Da.Fill(L1Ds);
TreeNode parentNode2 = childNode;
for (int j = 0; j < L1Ds.Tables[0].Rows.Count; j++)
{
DataRowView L1drv = L1Ds.Tables[0].DefaultView[j];
TreeNode childNode2 = new TreeNode();
childNode2.Text = L1drv[1].ToString().Trim();
childNode2.Value = L1drv[0].ToString().Trim();
childNode2.Expanded = (L1drv[0].ToString().Trim() == l1) ? true : false;
childNode2.SelectAction = TreeNodeSelectAction.Expand;
parentNode2.ChildNodes.Add(childNode2);
string L2Sql = "select L2,material,inv_code from inv_master where L0='" + L0drv[0].ToString().Trim() + "' and L1='" + L1drv[0].ToString().Trim() + "' and L2<>'0' and isvisible='Y' order by L2";
SqlDataAdapter L2Da = new SqlDataAdapter(L2Sql, myConn.con);
DataSet L2Ds = new DataSet();
L2Da.Fill(L2Ds);
TreeNode parentNode3 = childNode2;
for (int k = 0; k < L2Ds.Tables[0].Rows.Count; k++)
{
DataRowView L2drv = L2Ds.Tables[0].DefaultView[k];
TreeNode childNode3 = new TreeNode();
childNode3.Text = L2drv[1].ToString().Trim();
childNode3.Value = L2drv[2].ToString().Trim();
parentNode3.ChildNodes.Add(childNode3);
}
}
}
myConn.con.Close();
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)//当物料改变时
{
Label1.Text = "物料名称:" + TreeView1.SelectedNode.Text;
int inv_code = Convert.ToInt32(TreeView1.SelectedNode.Value);
}
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
华润微申购什么时候上市? 老公不带避孕套导致老婆两次打胎说明什么 男友不爱戴套套怎么办? ...中的男人都那么自私自利,只顾自己享受,不用避孕套保护女友,而是经常... 剪下一断苹果枝会长出根来吗 和平精英 和平精英循环脸怎么解决? 和平精英什么情况下弹人脸识别 如何避免触发人脸 Winxp sp2 英文版如何安装补丁 xp64位英文版怎么安装?因为网上只有英文版在64位win7系统运行下有共有... 关于安装英文版XP操作系统 遇到男人说你负责貌美如花我负责赚钱养家怎样回答? 她说生了小孩,变丑了,变黄婆了,到时你带小孩,我负责貌美如花,我应该怎么回复? 电影「明日世界」高清1280P播放或BT种子迅雷下载有么??? 明日世界迅雷高清BD种子——下载——在哪里? 明日世界电影高清完整版迅雷BT种子下载在哪? 明日世界电影高清完整版迅雷BT种子下载在哪 电影明日世界高清720P视频迅雷BT种子下载在哪儿? 腾讯客服人工电话95188怎么找回? 两瓶各60毫升的防晒霜加90克的牙膏可不可以带上飞机? 爱放牧(兴安盟)生物质新材料公司算是兴安盟的龙头企业么? 小学生组织六一儿童节文艺汇演 什么歌曲比较适合合唱 幼儿文艺汇演除了舞蹈还可以表演什么 微信里的微粒贷我怎么没有呢? 我的猫似乎被老鼠夹夹过,爪子露骨,开始腐烂,怎么办? 小区草丛里放老鼠夹,夹着的不是老鼠而是猫 猫被老鼠夹夹伤了,急! 猫咪的腿被老鼠夹夹断了已经消炎怎么这么办?急急急 放老鼠夹夹到猫违法吗 为什么老鼠夹夹不到猫?怎样才能夹到猫?谢谢! 铁猫打老鼠用什么食物? 大家搬冰箱洗衣机一般是怎么个搬法 asp.net2008(C#)中treeview怎么动态绑定数据库,父节点和子节点在两张表中,如何实现? excel错误报告后文档卡死然后文档不见了?怎么办?文档去哪了?怎么找回来? 戴尔笔记本电脑网络位置的ECap是什么? ecapexe是不是监视器? 电子产品中标识ECAP和TCAP有什么区别 求教,用这个视频设备拍完照后的照片在哪里 惠普Presario CQ43摄像头问题!!!急 点击ecap的时 QQ设置里面看到没有安装摄像头 hpg6-2146tx笔记本摄像头打开显示没有视屏捕捉硬件,windows7的,装的是ecap.是 联想G460笔记本装WIN7,如何显示摄像头? 电脑可不可以像手机一样拍照啊 我是东芝的本子 WIN7 系统 摄像头不能打开 摄像头ID USB&#92;VID_0000&PID_0000&#92;6&94F6559&0&3 求驱动 (C#)中treeview怎么绑定xml! asp.net2008(C#)中treeview怎么动态绑定数据库,父节点和子节点在两张表中,如何实现?麻烦问你下! .NET里的TreeView怎么实现动态绑定? 什么是玻璃钢喷涂,玻璃钢喷涂有什么优缺点 问道武当里面的配乐叫什么名字? 出彩中国人蒙眼平衡术背景音乐 央视 问道武当 的背景音乐 配乐 叫什么啊 局中人沈伯年死在第几集?