长度不能小于 0。
参数名: length说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 长度不能小于 0。
参数名: length源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。堆栈跟踪: 麻烦各位给看一下,谢谢
[ArgumentOutOfRangeException: 长度不能小于 0。
参数名: length]
   System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +7495991
   System.String.Substring(Int32 startIndex, Int32 length) +11
   Maticsoft.Web.inc.top.Bind() in D:\work\ThreelayerSolution\Web\inc\top.ascx.cs:39
   Maticsoft.Web.inc.top.Page_Load(Object sender, EventArgs e) in D:\work\ThreelayerSolution\Web\inc\top.ascx.cs:22
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

解决方案 »

  1.   

    先判断下吧
    if(length>0) 
    然后在执行啊
      

  2.   

    代码呢?
    判断前再加个是否null
      

  3.   

    把你出错的代码贴出来 void Bind()
            {
                DataSet ds = new Maticsoft.BLL.Tab_GuangGao().GetList(8, " type='3'", " addTime desc");
                String pics = null;
                String links = null;
                String texts = null;            foreach (DataRow row in ds.Tables[0].Rows)
                {
                    pics += row["address"] + "|";
                    links += row["link"] + "|";
                    texts += row["title"] + "|";
                }            if(pics.Length  >= 1 && texts.Length>= 1 &&  links.Length>= 1)
                {
    img_hidden.Value = pics.Substring(0, pics.Length);
    title_hidden.Value = texts.Substring(0, texts.Length);
    link_hidden.Value = links.Substring(0, links.Length);
                }
       
            }
      

  4.   

    把你出错的代码贴出来 void Bind()
            {
                DataSet ds = new Maticsoft.BLL.Tab_GuangGao().GetList(8, " type='3'", " addTime desc");
                String pics = null;
                String links = null;
                String texts = null;            foreach (DataRow row in ds.Tables[0].Rows)
                {
                    pics += row["address"] + "|";
                    links += row["link"] + "|";
                    texts += row["title"] + "|";
                }            if(pics.Length  >= 1 && texts.Length>= 1 &&  links.Length>= 1)
                {
    img_hidden.Value = pics.Substring(0, pics.Length);
    title_hidden.Value = texts.Substring(0, texts.Length);
    link_hidden.Value = links.Substring(0, links.Length);
                }
       
            }
     String pics = null;
                 String links = null;
                 String texts = null;
    这里定义改成String pics = "";
                 String links = "";
                 String texts = ""
    再试试
      

  5.   

    把你出错的代码贴出来 void Bind()
            {
                DataSet ds = new Maticsoft.BLL.Tab_GuangGao().GetList(8, " type='3'", " addTime desc");
                String pics = null;
                String links = null;
                String texts = null;            foreach (DataRow row in ds.Tables[0].Rows)
                {
                    pics += row["address"] + "|";
                    links += row["link"] + "|";
                    texts += row["title"] + "|";
                }            if(pics.Length  >= 1 && texts.Length>= 1 &&  links.Length>= 1)
                {
    img_hidden.Value = pics.Substring(0, pics.Length);
    title_hidden.Value = texts.Substring(0, texts.Length);
    link_hidden.Value = links.Substring(0, links.Length);
                }
       
            }
     String pics = null;
                 String links = null;
                 String texts = null;
    这里定义改成String pics = "";
                 String links = "";
                 String texts = ""
    再试试改过来试了,还是不行,
      

  6.   

    把你出错的代码贴出来 void Bind()
            {
                DataSet ds = new Maticsoft.BLL.Tab_GuangGao().GetList(8, " type='3'", " addTime desc");
                String pics = null;
                String links = null;
                String texts = null;            foreach (DataRow row in ds.Tables[0].Rows)
                {
                    pics += row["address"] + "|";
                    links += row["link"] + "|";
                    texts += row["title"] + "|";
                }            if(pics.Length  >= 1 && texts.Length>= 1 &&  links.Length>= 1)
                {
    img_hidden.Value = pics.Substring(0, pics.Length);
    title_hidden.Value = texts.Substring(0, texts.Length);
    link_hidden.Value = links.Substring(0, links.Length);
                }
       
            }
     String pics = null;
                 String links = null;
                 String texts = null;
    这里定义改成String pics = "";
                 String links = "";
                 String texts = ""
    再试试改过来试了,还是不行,额,  String pics = null;  String  改成小写string
      

  7.   


    把你出错的代码贴出来 void Bind()
            {
                DataSet ds = new Maticsoft.BLL.Tab_GuangGao().GetList(8, " type='3'", " addTime desc");
                String pics = null;
                String links = null;
                String texts = null;            foreach (DataRow row in ds.Tables[0].Rows)
                {
                    pics += row["address"] + "|";
                    links += row["link"] + "|";
                    texts += row["title"] + "|";
                }            if(pics.Length  >= 1 && texts.Length>= 1 &&  links.Length>= 1)
                {
    img_hidden.Value = pics.Substring(0, pics.Length);
    title_hidden.Value = texts.Substring(0, texts.Length);
    link_hidden.Value = links.Substring(0, links.Length);
                }
       
            }
     String pics = null;
                 String links = null;
                 String texts = null;
    这里定义改成String pics = "";
                 String links = "";
                 String texts = ""
    再试试改过来试了,还是不行,额,  String pics = null;  String  改成小写string我发现删掉这个文件还是报一样的错,而且这个路径D:\work\ThreelayerSolution\Web\inc\top.ascx.cs也和服务器上面的路径不一致
      

  8.   

    报错似乎是在  Substring 的时候 第2个参数截取的长度 超过了