TreeView 第一次只取第一階
来源:互联网 发布:微信小程序业务域名 编辑:程序博客网 时间:2024/06/05 00:56
aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testtree2.aspx.cs" Inherits="testtree2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView1" runat="server" ExpandDepth="0" ImageSet="XPFileExplorer" NodeIndent="15" EnableClientScript="false" OnTreeNodePopulate="PopulateNode">
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
VerticalPadding="0px" />
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="2px"
NodeSpacing="0px" VerticalPadding="2px" />
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
</asp:TreeView>
</div>
</form>
</body>
</html>
cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient;
// ODP.NET Import(s)
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
public partial class testtree2 : System.Web.UI.Page
{
//private const string dbConnString = "Data Source=testdb;User ID=myerp; Password=myerp;";
OracleDataAccess oda = new OracleDataAccess("TestConnectionString");
public string pid = "1";
//private const string cataQuery = "SELECT * FROM DAT_CATA";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TreeView1.Nodes.Clear();
AddTree(Int32.Parse(pid), (TreeNode)null);
}
}
protected void PopulateNode(Object sender, TreeNodeEventArgs e)
{
// 判斷節點深度
switch (e.Node.Depth)
{
case 0:
// 產生第一層節點
AddTree(Int32.Parse(pid), e.Node);
break;
case 1:
//產生第二層節點
AddTree(Int32.Parse(pid), e.Node);
break;
default:
break;
}
}
public void AddTree(int ParentID, TreeNode pNode)
{
string sql = "SELECT CATA_ID, CATA_NAME, CATA_PID, CATA_NO FROM BASE_CATA";
DataSet ds = oda.getDataSet(sql);
DataView dvTree = new DataView(ds.Tables[0]);
if (pNode == null)
{
dvTree.RowFilter = "[CATA_PID] = 1";
}
else
{
dvTree.RowFilter = "[CATA_PID] = " + pNode.Value;
}
foreach (DataRowView Row in dvTree)
{
TreeNode Node = new TreeNode();
Node.PopulateOnDemand = true;
Node.SelectAction = TreeNodeSelectAction.Expand;
if (pNode == null)
{
Node.Text = Row["CATA_NAME"].ToString();
Node.Value = Row["CATA_ID"].ToString();
TreeView1.Nodes.Add(Node);
Node.Expanded = false;
}
else
{
Node.Text = Row["CATA_NAME"].ToString();
Node.Value = Row["CATA_ID"].ToString();
pNode.ChildNodes.Add(Node);
Node.Expanded = false;
}
}
}
}
- TreeView 第一次只取第一階
- 获取CPU序列号(多个CPU,只取第一个)
- sql语句,查出多条数据只取第一条
- 取TreeView節點
- 只判断第一次加载
- 只取数据库中出现的满足条件的第一条记录
- 初学者教程:第一只爬虫——爬取招聘信息(一)
- 初学者教程:第一只爬虫——爬取招聘信息(二)
- 初学者教程:第一只爬虫——爬取招聘信息(三)
- 取得数据表中前N条记录,某列重复的话只取第一条记录
- vs2005 treeview checkbox 取值
- 第一次图像取反
- sql语句 一个字段有好多重复的数据,但只取第一次填进去的数据
- date_format只取日期
- 第一个的第一次
- 第一堂第一次
- 第一只虫子
- 第一只博客
- 图像分割
- asp.net的web.config节点详解
- Linux嵌入式系统与硬件平台的关系
- 使用avr-libc的标准IO流调试程序
- Eclipse Eclipseme wtk配置JAVA ME开发环境
- TreeView 第一次只取第一階
- 程序员8荣8耻
- C#增加连续的动态控件并取值的例子
- OPC数据读写之订阅方式(Subscription)与COM可连接对象的应用分析
- 专业人生, 从专业博客开始
- Windows_CMD实用技巧
- SuSE的吉祥物
- 如何结合使用Subversion 和Eclipse进行SVN管理
- Symbian S60 如何检测文件是否存在