第一次使用treeView时遇到问题,不知道怎么解决了

时间:2021-11-22 06:42:56
在treeView里显示出数据来了
现在就点击上面的某个标题时
把关于这条的信息显示出来.
现在就是点击没有反映.
TreeView1_SelectedIndexChange 和 TreeView1_Check
在这里头写代码无即于是

显示数据代码如下所示
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source='" + HttpContext.Current.Server.MapPath("~/LHB_DataBase/rss.mdb") + "';Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
OleDbConnection cn = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();

private void TreeViewOpeartor()
{
this.TreeView1.Nodes.Clear();
string OledbString = "select * from categories ";
DataTable rss_Url = this.GetRss_Url();
cn.ConnectionString = connectionString;
cn.Open();
cmd.Connection = cn;
cmd.CommandText = OledbString;
OleDbDataReader dda = cmd.ExecuteReader();
while(dda.Read())
{
TreeNode theNode = new TreeNode ();
theNode.Text = dda["categoryname"].ToString();
theNode.NodeData = dda["ID"].ToString();
this.TreeView1.Nodes.Add(theNode);
DataRow[] urls = rss_Url.Select("categoryID=" + dda["ID"].ToString());
for(int i = 0 ; i < urls.Length ; i++)
{
Microsoft.Web.UI.WebControls.TreeNode node = new Microsoft.Web.UI.WebControls.TreeNode();
node.Text = urls[i]["Rss_name"].ToString();
node.Target = urls[i]["Id"].ToString();
node.NodeData = urls[i]["ID"].ToString();
theNode.Nodes.Add(node);
}
}
dda.Close();
cn.Close();
}


private DataTable GetRss_Url()
{
cn.ConnectionString = connectionString ;
OleDbDataAdapter dda = new OleDbDataAdapter("select * from rss where releasetoweb=1 ",cn);
DataTable dt = new DataTable();
dda.Fill(dt);
return dt;
}

8 个解决方案

#1



窗体加载时代码下面
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.Page.IsPostBack)
{
TreeViewOpeartor();
}
}

下面TreeView1的是单击事件
private void TreeView1_Check(object sender, Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e)
{
TreeNode node = this.TreeView1.GetNodeFromIndex(this.TreeView1.SelectedNodeIndex);
string id = node.ToString();
this.lblMessage.Text = id;
this.Response.Redirect("~/Test.aspx?id =" + id,true);
}

为什么我点击标题时怎么就不执行TreeView1_Check事件

#2


up

---------------------------------------------------------------------------------------------
腰缠70元到月入近10万
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=453

IT工程师 毕业4年我年薪涨到30万 
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=511

26岁青年坐拥千万域名资产 从小玩家变成CEO 
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=515

程序员的酸甜苦辣:告别Coding 
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=341

从月薪3500到700万(一)
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=170

网络草根月赚3000的十种方法
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=517

如果我是女的 我肯定不会嫁给做网站的
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=512

#3


做广告的真多

#4


DEBUG一下。。看一下每一步的值吧。。

#5


应该使用 afteSelect哪个事件吧~

#6


DEBUG一下。。看一下每一步的值吧。。
~~~~~~~
       进入单步进,进不了TreeView1_Check这个事件里去呀

应该使用 afteSelect哪个事件吧~
         ~~~~~~~~~~~
         怎么找不到这个事件呢

#7


进入单步进,进不了TreeView1_Check这个事件里去呀
=============================================
不是吧,看看跟事件处理程序关联起来没有:
this.treeView1.Check += ...


afteSelect 说的应是AfterSelect...

#8


#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.TreeView1.Check += new Microsoft.Web.UI.WebControls.ClickEventHandler(this.TreeView1_Check);
this.btnShowInformation.Click += new System.EventHandler(this.btnShowInformation_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


自动生成的代码在这里
this.TreeView1.Check += new Microsoft.Web.UI.WebControls.ClickEventHandler(this.TreeView1_Check);
这个就是你说的那个事件处理程序吧

这个好像不顶事呢

#1



窗体加载时代码下面
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.Page.IsPostBack)
{
TreeViewOpeartor();
}
}

下面TreeView1的是单击事件
private void TreeView1_Check(object sender, Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e)
{
TreeNode node = this.TreeView1.GetNodeFromIndex(this.TreeView1.SelectedNodeIndex);
string id = node.ToString();
this.lblMessage.Text = id;
this.Response.Redirect("~/Test.aspx?id =" + id,true);
}

为什么我点击标题时怎么就不执行TreeView1_Check事件

#2


up

---------------------------------------------------------------------------------------------
腰缠70元到月入近10万
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=453

IT工程师 毕业4年我年薪涨到30万 
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=511

26岁青年坐拥千万域名资产 从小玩家变成CEO 
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=515

程序员的酸甜苦辣:告别Coding 
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=341

从月薪3500到700万(一)
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=170

网络草根月赚3000的十种方法
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=517

如果我是女的 我肯定不会嫁给做网站的
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=512

#3


做广告的真多

#4


DEBUG一下。。看一下每一步的值吧。。

#5


应该使用 afteSelect哪个事件吧~

#6


DEBUG一下。。看一下每一步的值吧。。
~~~~~~~
       进入单步进,进不了TreeView1_Check这个事件里去呀

应该使用 afteSelect哪个事件吧~
         ~~~~~~~~~~~
         怎么找不到这个事件呢

#7


进入单步进,进不了TreeView1_Check这个事件里去呀
=============================================
不是吧,看看跟事件处理程序关联起来没有:
this.treeView1.Check += ...


afteSelect 说的应是AfterSelect...

#8


#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.TreeView1.Check += new Microsoft.Web.UI.WebControls.ClickEventHandler(this.TreeView1_Check);
this.btnShowInformation.Click += new System.EventHandler(this.btnShowInformation_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


自动生成的代码在这里
this.TreeView1.Check += new Microsoft.Web.UI.WebControls.ClickEventHandler(this.TreeView1_Check);
这个就是你说的那个事件处理程序吧

这个好像不顶事呢