标题:为什么会出现索引和长度必须引用该字符串内的位置这样的错误
只看楼主
屎宝宝
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2012-3-19
结帖率:66.67%
 问题点数:0 回复次数:0 
为什么会出现索引和长度必须引用该字符串内的位置这样的错误
valuePath的值为什么一直是00呢?
程序代码:
Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Call Me.initTree()
        End If
    End Sub
    Sub initTree()
        Dim valuePath As String
        Dim i As Integer
        Dim o As New myData.clsTree
        Dim dr As SqlClient.SqlDataReader
        Dim dv As DataView
        dv = o.getall2ds(" User_id='admin'").Tables(0).DefaultView
        dr = o.getall2dr("")
        Dim myNode As TreeNode
        While dr.Read
            myNode = New TreeNode
            myNode.Expanded = False

            myNode.Value = dr.Item("Typeid").ToString
            dv.RowFilter = " Typeid='" & myNode.Value & "'"
            If dv.Count = 0 Then
                Continue While
            End If
            myNode.Text = dr.Item("FullName").ToString
            'myNode.ImageUrl = dr.Item("imgUrl").ToString
            If dr.Item("isGroup") = "0" Then
                myNode.Target = "WebForm1"
                myNode.NavigateUrl = "WebForm1.aspx"
            Else
                myNode.NavigateUrl = ""
            End If
            If dr.Item("Parid") = "0" Then
                Me.TreeView1.Nodes.Add(myNode)
            Else
                valuePath = ""
                For i = 1 To dr.Item("Parid").ToString.Length / 2
                    If valuePath = "" Then
                        valuePath = dr.Item("Parid").ToString.Substring(0, i * 2)
                    Else
                        valuePath &= "/" & dr.Item("Parid").ToString.Substring(0, i * 2)
                    End If
                Next
                If Not Me.TreeView1.FindNode(valuePath) Is Nothing Then
                    Me.TreeView1.FindNode(valuePath).ChildNodes.Add(myNode)
                End If

            End If
        End While
        dr.Close()
    End Sub
   
End Class


[ 本帖最后由 屎宝宝 于 2013-6-3 18:27 编辑 ]
搜索更多相关主题的帖子: 字符串 
2013-06-03 18:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-414444-1-1.html




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

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