
// aspx //
<%@ Page language="c#" Codebehind="WebForm1aspxcs" AutoEventWireup="false" Inherits="TreeTestWebForm1" %>
<%@ Register TagPrefix="iewc" Namespace="MicrosoftWebUIWebControls" Assembly="MicrosoftWebUIWebControls" %>
<HTML>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<iewc:TreeView id="TreeView1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 16px" runat="server"
AutoPostBack="True"></iewc:TreeView>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 440px; POSITION: absolute; TOP: 56px" runat="server"
Width="152px" Height="64px">Label</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 103; LEFT: 456px; POSITION: absolute; TOP: 144px" runat="server"
Width="144px" Height="48px">Label</asp:Label>
<asp:Label id="Label3" style="Z-INDEX: 104; LEFT: 696px; POSITION: absolute; TOP: 64px" runat="server">Label</asp:Label></FONT>
</form>
</body>
</HTML>
// CS //
using System;
using SystemCollections;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemWeb;
using SystemWebSessionState;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemWebUIHtmlControls;
using SystemDataOleDb;
using MicrosoftWebUIWebControls;
namespace TreeTest
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : SystemWebUIPage
{
protected MicrosoftWebUIWebControlsTreeView TreeView1;
protected SystemWebUIWebControlsLabel Label1;
protected SystemWebUIWebControlsLabel Label2;
protected SystemWebUIWebControlsLabel Label3;
OleDbConnection Con ;
string dataConStr = "";
private void Page_Load(object sender, SystemEventArgs e)
{
dataConStr = "Provider=microsoftjetoledb40;Data Source="+ServerMapPath("treemdb")+";User ID=;Password=;";
Con = new OleDbConnection(dataConStr);
if(!IsPostBack)
{
TreeNode node = new TreeNode();
nodeText = "根";
nodeNodeData = "0";
TreeView1NodesAdd(node); // 添加根
AddTestNodes(node); //添加"展开"节点
}
}
private void AddTestNodes(TreeNode node)
{
TreeNode testnode = new TreeNode();
testnodeText = "正在展开";
testnodeNodeData = "testnode";
nodeNodesAdd(testnode);
}
private void AddNodes(TreeNode node)
{
string parentID = "0";
if(nodeParent != null)
{
parentID = nodeNodeData;
}
// deeptree 为表名
string cmdstr = "select from deeptree where parentid="+parentID;
OleDbCommand cmd = new OleDbCommand(cmdstr,Con);
try
{
ConOpen();
OleDbDataReader reader = cmdExecuteReader();
while(readerRead())
{
TreeNode childNode = new TreeNode();
childNodeText = reader["content"]ToString();
childNodeNodeData = reader["id"]ToString();
// 判断是否有子节点 //
// deeptree 为表名
cmdstr = "select count() from deeptree where parentid="+childNodeNodeData;
OleDbConnection Con1 = new OleDbConnection(dataConStr);
OleDbCommand cmd1 = new OleDbCommand(cmdstr,Con1);
Con1Open();
OleDbDataReader reader1 = cmd1ExecuteReader();
if(reader1Read())
{
if(SystemConvertToInt32(reader1[0]) > 0)
{
AddTestNodes(childNode); // 若有子节点,则添加测试节点
}
}
reader1Close();
Con1Close();
// //
nodeNodesAdd(childNode);
}
}
catch(Exception ex)
{
Label3Text = exMessage;
}
finally
{
if(ConState != ConnectionStateClosed)
ConClose();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASPNET Web 窗体设计器所必需的。
//
InitializeComponent();
baseOnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
thisTreeView1Expand += new MicrosoftWebUIWebControlsClickEventHandler(thisTreeView1_Expand);
thisLoad += new SystemEventHandler(thisPage_Load);
}
#endregion
private void TreeView1_Expand(object sender, MicrosoftWebUIWebControlsTreeViewClickEventArgs e)
{
Label1Text = eNode;
TreeNode node = new TreeNode();
node = TreeView1GetNodeFromIndex(eNode);
//node = TreeView1GetNodeFromIndex("02");
if(node != null)
{
Label2Text = nodeNodeData;
// 判断该节点下子节点数,若1个且为testnode说明未填充所以子节点
if((nodeNodesCount == 1)&& (nodeNodes[0]NodeData == "testnode"))
{
nodeNodesClear(); //清空
AddNodes(node); // 填充子节点
}
}
}
}
}
给你一段我曾经写的代码,主要是生成TreeView的节点!有什么不懂的地方你就提!
Public Sub InitializeTreeView(ByVal strvXL As TreeView, ByVal vrsRecordTwo As DataSet)
Dim treBaseNodeOne As TreeNode
Dim treBaseNodeTwo As TreeNode
Dim strDWDM As String
m_rsRecordTwo = g_clsSybaseSelectSC_PD_SBCSB1()
'查找供电局信息
g_clsSybaseSelectRS_ZZJG_ZZJGDMB(m_rsRecordOne)
'添加根节点
Do While m_rsRecordOneRead
strDWDM = m_rsRecordOneGetString(0) '获取单位代码
treBaseNodeOne = New TreeNode
treBaseNodeOneText = m_rsRecordOneGetString(1)Trim() '获取单位名称
treBaseNodeOneName = m_rsRecordOneGetString(1)
treBaseNodeOneTag = ""
strvXLNodesAdd(treBaseNodeOne)
'添加树结构第二层
Dim drsTwo() As DataRow
drsTwo = m_rsRecordTwoTables(0)Select("SSDW='" & strDWDM & "' and SC__XLBM is null")
For Each dr As DataRow In drsTwo
treBaseNodeTwo = New TreeNode
treBaseNodeTwoText = drItem("XLMC")ToStringTrim
treBaseNodeTwoName = drItem("XLMC")
treBaseNodeTwoTag = drItem("XLBM")
treBaseNodeOneNodesAdd(treBaseNodeTwo)
Next
Loop
m_rsRecordOneClose()
End Sub
一句两句说不清楚,给个代码大家交流哈,我也是学编程的
import javasql;
import javaio;
public class Test13{
public static void main(String[] args) throws Exception{
ClassforName("sunjdbcodbcJdbcOdbcDriver");
Connection conn = DriverManagergetConnection("jdbc:odbc:folkmusic");
Statement stmt = conncreateStatement();
ResultSet rs = stmtexecuteQuery("select from main");
ClassforName("oraclejdbcdriverOracleDriver");
Connection conn1 = DriverManagergetConnection("jdbc:oracle:thin:@127001:1521:java","java1","test123");
//conn1setAutoCommit(false);
while(rsnext()){
String content = rsgetString("content");
BufferedWriter bw = new BufferedWriter(new FileWriter("tmpfiletxt"));
bwwrite(content);
bwflush();
bwclose();
PreparedStatement stmt1 = conn1prepareStatement("insert into main (content) values ()");
InputStream is = new FileInputStream(new File("tmpfiletxt");
stmt1setBinaryStream(1,is,isavailable());
stmt1executeUpdate();
}
//conn1commit();
rsclose();
//stmt1close();
}
};
以上就是关于如何 在TREEVIEW载入数据库全部的内容,包括:如何 在TREEVIEW载入数据库、vb.net从数据库读取信息填充treeview做成层次目录怎么做、java问题,怎样从数据库动态获得jtree节点等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)