| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 583 人关注过本帖
标题:求助。修改newsadd中对findnode方法的递归调用;
只看楼主 加入收藏
elenaa
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-6-13
收藏
 问题点数:0 回复次数:0 
求助。修改newsadd中对findnode方法的递归调用;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class newadd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
            Response.Redirect("login.aspx", true);
        if (!IsPostBack)
        {
            init_treeView();

            if (Request.QueryString["id"] != null)
            {
                test.business.news news = new test.business.news(int.Parse(Request.QueryString["id"]));
                this.title.Text = news.Title;
                this.author.Text = news.Author;
                this.newsbody.Text = news.Body;
                this.audit.Checked = news.isAudit;
                TreeNode tn=new TreeNode() ;
                //改错1、修改方法调用
                 this.findNode(news.NewsCata,tn, this.TreeView1.Nodes);
                this.newscata.Text = tn.Text;
                this.hidetext.Text = tn.Value;
                if (news.isAudit)
                    this.Button1.Enabled = false;
            }
            else
            {
                this.audit.Visible = false;
            }
            this.Panel1.Visible = false;
        }
    }
    private void init_treeView()
    {
        test.data.dataconnection da = new test.data.dataconnection();
        DataTable dt = da.readdate("select * from cata");
        TreeNode[] node = new TreeNode[dt.Rows.Count];
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            node[i] = new TreeNode(dt.Rows[i]["cataname"].ToString(), dt.Rows[i]["id"].ToString());
        }
        for (int i = 0; i < node.Length; i++)
        {
            DataView dv = dt.DefaultView;
            dv.RowFilter = "cataname='" + node[i].Text + "'";
            if (dv[0]["topid"].ToString() == "0")
                this.TreeView1.Nodes.Add(node[i]);
            else
            {
                dv.RowFilter = "id=" + dv[0]["topid"].ToString();
                for (int j = 0; j < node.Length; j++)
                    if (node[j].Text == dv[0]["cataname"].ToString())
                    { node[j].ChildNodes.Add(node[i]); break; }
            }
        }
    }
    private void findNode(int id, ref TreeNode tn, TreeNodeCollection nodes)
    {
        foreach (TreeNode node in nodes)
        {
            if (id.ToString() == node.Value)
            {
                tn = node;
                break;
            }
            if (node.ChildNodes.Count > 0)
            {
                //改错1、修改方法调用

                findNode(id, tn, node.ChildNodes);

            }
        }
    }
   
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.Panel1.Visible = true;
    }
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        this.newscata.Text = this.TreeView1.SelectedNode.Text;
        this.hidetext.Text = this.TreeView1.SelectedValue;
        this.Panel1.Visible = false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //4、添加代码,根据新闻是新发布还是修改的,分别调用news类的publishNews方法和updateNews保存新闻
        test.data.dataconnection da = new test.data.dataconnection();
        SqlParameter[] sp = new SqlParameter[2];
        sp[0] = new SqlParameter("@author", author.Text);
        sp[1] = new SqlParameter("@title", title.Text);
        DataTable dt=da.readdate ("select count(*) from news where author=@author and title=@title",sp);
        if (Convert.ToInt32(dt.Rows[0][0]) == 0)
            test.business.news.publishNews();
        else test.business.news.updateNews();
    }
    }
}
搜索更多相关主题的帖子: public null 
2013-06-13 16:20
快速回复:求助。修改newsadd中对findnode方法的递归调用;
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016352 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved