If child.Text.ToString = TextBox1.Text.ToString Then
这句有点问题:应使用:child.Text.ToString.Equals(TextBox1.Text),如果不理解,请查相应的参考书,看看比较字符串相等时这两者有何不同。其它的地方没看出有什么问题。
这句有点问题:应使用:child.Text.ToString.Equals(TextBox1.Text),如果不理解,请查相应的参考书,看看比较字符串相等时这两者有何不同。其它的地方没看出有什么问题。
class Test
{
public static void Main()
{
// Numeric equality: True
Console.WriteLine((2 + 2) == 4); // Reference equality: different objects, same boxed value: False
object s = 1;
object t = 1;
Console.WriteLine(s == t); // Define some string
string a = "hello";
string b = String.Copy(a);
string c = "hello"; // compare string values for a constant and an instance: True
Console.WriteLine(a == b);
// compare string references;
// a is a constant but b is an instance: False
Console.WriteLine((object)a == (object)b); // compare string references, both constants have the same value,
// so string interning points to same reference: True
Console.WriteLine((object)a == (object)c);
}
}
True
False
True
False
True
对应il的装箱和拆箱可是一般来说是能自动完成的要不我把源代码贴上你看看
下面的代码就是啦。
private void Button1_Click(object sender, System.EventArgs e)
{
string TreeNodeIndex;
for(int i = 0; i < TreeView1.Nodes.Count; i++)
{
TreeNodeIndex = FindByValue(TreeView1.Nodes[i],TextBox1.Text);
if(!(TreeNodeIndex.Equals("")))
{
TreeView1.SelectedNodeIndex = TreeNodeIndex;
TreeView1.DataBind();
break;
}
}}
string FindByValue(Microsoft.Web.UI.WebControls.TreeNode Node,string Text)
{
string TreeNodeIndex = "";
if(Node.Text.Equals(Text))
{
TreeNodeIndex = Node.GetNodeIndex();
return TreeNodeIndex;
} for(int i = 0; i < Node.Nodes.Count; i++)
{
TreeNodeIndex = FindByValue(Node.Nodes[i],TextBox1.Text);
if(!(TreeNodeIndex.Equals("")))
{
return TreeNodeIndex;
}
}
return "";
}
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="findtree.WebForm1" %>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<iewc:TreeView id="TreeView1" style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 64px"
runat="server">
<iewc:TreeNode Text="Node0" Expanded="True"></iewc:TreeNode>
<iewc:TreeNode Text="Node1"></iewc:TreeNode>
<iewc:TreeNode Text="Node2">
<iewc:TreeNode Text="Node6"></iewc:TreeNode>
<iewc:TreeNode Text="Node7"></iewc:TreeNode>
<iewc:TreeNode Text="Node8"></iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode Text="Node3">
<iewc:TreeNode Text="Node9"></iewc:TreeNode>
<iewc:TreeNode Text="Node10"></iewc:TreeNode>
<iewc:TreeNode Text="Node11"></iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode Text="Node4"></iewc:TreeNode>
<iewc:TreeNode Text="Node5"></iewc:TreeNode>
</iewc:TreeView>
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 256px; POSITION: absolute; TOP: 96px" runat="server">Node0</asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 280px; POSITION: absolute; TOP: 64px" runat="server"
Text="Find"></asp:Button></FONT>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;namespace findtree
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
private void Page_Load(object sender, System.EventArgs e)
{
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string TreeNodeIndex;
for(int i = 0; i < TreeView1.Nodes.Count; i++)
{
TreeNodeIndex = FindByValue(TreeView1.Nodes[i],TextBox1.Text);
if(!(TreeNodeIndex.Equals("")))
{
TreeView1.SelectedNodeIndex = TreeNodeIndex;
TreeView1.DataBind();
break;
}
} }
string FindByValue(Microsoft.Web.UI.WebControls.TreeNode Node,string Text)
{
string TreeNodeIndex = "";
if(Node.Text.Equals(Text))
{
TreeNodeIndex = Node.GetNodeIndex();
return TreeNodeIndex;
} for(int i = 0; i < Node.Nodes.Count; i++)
{
TreeNodeIndex = FindByValue(Node.Nodes[i],TextBox1.Text);
if(!(TreeNodeIndex.Equals("")))
{
return TreeNodeIndex;
}
}
return "";
}
}
}
---------------------------------------
private bool FindAll(TreeNodeCollection nodes)
{
foreach(TreeNode node in nodes)
{
if(node.Text=="hoiu") //找到
{
//选中该节点
tvMain.SelectedNode=node;
return true;
}
}
//递归
if(node.Nodes.Count!=0)
FindAll(node.Nodes);
return false;
}
结贴有时间在帮我看看这个问题:(解决了那个500m空间送你)
http://community.csdn.net/Expert/topic/3249/3249116.xml?temp=.3563654