| |

VerySource

 Forgot password?
 Register
Search
View: 852|Reply: 3

Treeview problem in vs: index and length must refer to the position within the string. Parameter name: length

[Copy link]

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2021-3-9 16:30:02
| Show all posts |Read mode
When the value read from the database is in Chinese, the following error will occur when the node is expanded

The index and length must refer to the position within the string. Parameter name: length

What I used is:

Set PopulateOnDemand to true, and the child nodes are dynamically generated.
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2021-3-9 18:00:01
| Show all posts
This has nothing to do with Chinese, it should be a code problem.
Reply

Use magic Report

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2021-3-9 18:15:02
| Show all posts
private void BindTree()
    {
        YCSD.BLL.Account_Project bll = new YCSD.BLL.Account_Project();
        DataTable dt = bll.GetList(10,1,"FatherNode ='-1'").Tables[0];
        TreeNode myTreeNode;
        for(int i = 0;i<dt.Rows.Count;i++)
        {
            myTreeNode = new TreeNode();
            myTreeNode.Value = dt.Rows[i]["ProjectID"].ToString();
            myTreeNode.Text = dt.Rows[i]["ProjectID"].ToString()+dt.Rows[i]["ProjectName"].ToString();
            myTreeNode.PopulateOnDemand = true;
            TreeView1.Nodes.Add(myTreeNode);
        }
    }
    protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
        TreeNode newNode;
        YCSD.BLL.Account_Project bll = new YCSD.BLL.Account_Project();
        DataTable dt = bll.GetList(10, 1, "FatherNode ='" + e.Node.Value + "'").Tables[0];
        for (int i = 0; i <dt.Rows.Count; i++)
        {
            newNode = new TreeNode();
            newNode.Value = dt.Rows[i]["ProjectID"].ToString();
            newNode.Text = dt.Rows[i]["ProjectID"].ToString() + dt.Rows[i]["ProjectName"].ToString();
            //Set PopulateOnDemand to true to ensure that the child nodes below can still be dynamically generated.
            newNode.PopulateOnDemand = true;
            e.Node.ChildNodes.Add(newNode);
        }
    }
These are two methods: for English and numbers, there is no problem, if it is Chinese, there will be a problem.
Reply

Use magic Report

0

Threads

32

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2021-3-9 19:45:01
| Show all posts
It is estimated to be related to page encoding or database encoding. This is generally not touched. We have no problems here.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list