以下代码中的错误任何人都可以解决... [英] error in this below code any one solve plz........................

查看:79
本文介绍了以下代码中的错误任何人都可以解决...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"/dynamictreeview"应用程序中的服务器错误.
编译错误
说明:编译服务该请求所需的资源期间发生错误.请查看以下特定的错误详细信息,并适当地修改您的源代码.

编译器错误消息:CS0103:名称节点"在当前上下文中不存在

源错误:

Server Error in ''/dynamictreeview'' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name ''node'' does not exist in the current context

Source Error:

Line 88: newnode.PopulateOnDemand = true;
Line 89: 
Line 90: node.ChildNodes.Add(newnode);
Line 91: 
Line 92: }







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.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {

    }
    protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
        if (e.Node.ChildNodes.Count == 0)

{

switch (e.Node.Depth)

{

case 0:

fillcategory(e.Node);

break;

case 1:

fillsubcat(e.Node);

break;

}

}

}

    private void fillcategory(TreeNode treeNode)
    {
        SqlConnection con = new SqlConnection("Data Source=CIODEV03\\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True");

con.Open();

string qry = "select * from tbl_category";

SqlDataAdapter ad = new SqlDataAdapter(qry, con);

DataSet ds = new DataSet();

try

{

ad.Fill(ds);

}

catch (Exception ex)

{

}

if (ds.Tables[0].Rows.Count > 0)

{

foreach (DataRow r in ds.Tables[0].Rows)

{

TreeNode newnode = new TreeNode(r["catname"].ToString() , r["catid"].ToString());

newnode.PopulateOnDemand = true;

node.ChildNodes.Add(newnode);

}



}

    }

    


    private void fillsubcat(TreeNode treeNode)
    {
        string aid = node.Value;

SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

con.Open();

string qry = "select subcatid,subcatname from tbl_subcategory where catid='" + aid + "'";

SqlDataAdapter ad = new SqlDataAdapter(qry, con);

DataSet ds = new DataSet();

try

{

ad.Fill(ds);

}

catch (Exception ex)

{

}

if (ds.Tables[0].Rows.Count > 0)

{

foreach (DataRow r in ds.Tables[0].Rows)

{

TreeNode newnode = new TreeNode(r["subcatname"].ToString(), r["subcatid"].ToString());

newnode.PopulateOnDemand = false;

newnode.SelectAction = TreeNodeSelectAction.None;

node.ChildNodes.Add(newnode);

}
}
}
}

推荐答案

在此自解释错误消息中有哪些不清楚的地方?如何使用从未声明过的node?

—SA
What can be unclear in this self-explanatory error message? How can you use the node which you never declared?

—SA




根据我的理解,您正在尝试将该节点添加到树视图中.但这就是导致错误的代码.如果看到错误,

Hi,

As per my understanding you are trying to add the node to your treeview. But that is the code is where the error is caused.If you see the error ,

The name ''node'' does not exist in the current context



没有变量名为``node'',也没有指定要在哪里添加新节点,我想应该将newnode添加到作为参数传递的节点上.

试试



There is no variable with name as ''node''.Also, it doesnt specify where are you adding the new node.I guess that newnode should be added to the node passed as parameter.

Try

treeNode.ChildNodes.Add(newnode);



请参阅以下将节点添加到树状视图的链接.

http://stackoverflow.com/questions/881607/adding-child-nodes-in-treeview [^ ]

http://msdn.microsoft.com/en-us/library/aa984278 (v = vs.71).aspx [



Please see the below link on adding nodes to your treeview.

http://stackoverflow.com/questions/881607/adding-child-nodes-in-treeview[^]

http://msdn.microsoft.com/en-us/library/aa984278(v=vs.71).aspx[^]

Hope this helps.


我建​​议您清洗溶液.删除所有断点并重新构建.
然后尝试编译它
I would suggest you to Clean the solutions. remove all your breakpoints and build it again.
And then try to compile it


这篇关于以下代码中的错误任何人都可以解决...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆