asp.net中treeview控件如何使用如何绑定sqlserver数据库
4个回答
展开全部
动态绑定数据库里面的表作为树控件
显示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinqModel;
namespace WebDOCManager
{
public partial class MasterText : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
IList<bumenInfo> bList = BLL.BumenManager.GetBumenAll();
BindTreeView(bList,this.tvBumen.Nodes,"0");
}
}
/// <summary>
/// 动态添加树控件
/// </summary>
/// <param name="blist">部门信息</param>
/// <param name="tnc"></param>
/// <param name="pid"></param>
private void BindTreeView(IList<bumenInfo> blist,TreeNodeCollection tnc , string pid)
{
foreach(bumenInfo b in blist)
{
if (b.pid.ToString() == pid)
{
TreeNode tn = new TreeNode();
tn.Value = b.bid.ToString();
tn.Text = b.bname;
tn.NavigateUrl = "Default1.aspx?id="+tn.Value;
tnc.Add(tn);
BindTreeView(blist, tn.ChildNodes, tn.Value);
}
}
}
}
}
显示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinqModel;
namespace WebDOCManager
{
public partial class MasterText : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
IList<bumenInfo> bList = BLL.BumenManager.GetBumenAll();
BindTreeView(bList,this.tvBumen.Nodes,"0");
}
}
/// <summary>
/// 动态添加树控件
/// </summary>
/// <param name="blist">部门信息</param>
/// <param name="tnc"></param>
/// <param name="pid"></param>
private void BindTreeView(IList<bumenInfo> blist,TreeNodeCollection tnc , string pid)
{
foreach(bumenInfo b in blist)
{
if (b.pid.ToString() == pid)
{
TreeNode tn = new TreeNode();
tn.Value = b.bid.ToString();
tn.Text = b.bname;
tn.NavigateUrl = "Default1.aspx?id="+tn.Value;
tnc.Add(tn);
BindTreeView(blist, tn.ChildNodes, tn.Value);
}
}
}
}
}
展开全部
完整代码给10分估计太少了,不过我可以把思路告诉你
把for循环把根节点找出来,再在每个根节点里面for循环把子节点找出来,然后再把子节点添加到根节点,再把根节点邦定到Tree
我可以帮助你,你先设置我最佳答案后,我百度Hii教你。
把for循环把根节点找出来,再在每个根节点里面for循环把子节点找出来,然后再把子节点添加到根节点,再把根节点邦定到Tree
我可以帮助你,你先设置我最佳答案后,我百度Hii教你。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
strSQL= "select distinct year(ConsignDate) as 年份 from PostInputInfo order by 年份 desc ";
DataTable dtTemp=ds.GetTable(strSQL,false);
foreach(DataRow drTemp in dtTemp.Rows)
{
if(drTemp[0] !=DBNull.Value)
{
strYear=drTemp[0].ToString();
TreeNode node1=new TreeNode();
node1.Text =strYear + " 年 ";
this.tvwSheet.Nodes.Add(node1);
strSQL= "select distinct month(ConsignDate) as 月份 from PostInputInfo where year(ConsignDate)= " + strYear + " order by 月份 ";
DataTable dt=ds.GetTable(strSQL,false);
foreach(DataRow dr in dt.Rows)
{
strMonth=dr[0].ToString();
TreeNode node2=new TreeNode();
node2.Text =strMonth + " 月 ";
node1.Nodes.Add(node2);
}
}
}
DataTable dtTemp=ds.GetTable(strSQL,false);
foreach(DataRow drTemp in dtTemp.Rows)
{
if(drTemp[0] !=DBNull.Value)
{
strYear=drTemp[0].ToString();
TreeNode node1=new TreeNode();
node1.Text =strYear + " 年 ";
this.tvwSheet.Nodes.Add(node1);
strSQL= "select distinct month(ConsignDate) as 月份 from PostInputInfo where year(ConsignDate)= " + strYear + " order by 月份 ";
DataTable dt=ds.GetTable(strSQL,false);
foreach(DataRow dr in dt.Rows)
{
strMonth=dr[0].ToString();
TreeNode node2=new TreeNode();
node2.Text =strMonth + " 月 ";
node1.Nodes.Add(node2);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
datasoure 属性绑定
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询