注册 登录
编程论坛 ASP.NET技术论坛

StartIndex 不能小于 0。参数名: startIndex

wangjian_g 发布于 2008-11-27 16:24, 3052 次点击
“/myDataList”应用程序中的服务器错误。
--------------------------------------------------------------------------------

StartIndex 不能小于 0。参数名: startIndex
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.ArgumentOutOfRangeException: StartIndex 不能小于 0。参数名: startIndex

源错误:


行 158:        public String FormatPhotoUrl(String PhotoUrl)
行 159:        {   
行 160:            return(Request.ApplicationPath + "/UpLoads/Photoes/"  + PhotoUrl.Substring(PhotoUrl.LastIndexOf("/"),
行 161:                PhotoUrl.Length - PhotoUrl.LastIndexOf("/")));
行 162:        }
 public String FormatPhotoUrl(String PhotoUrl)
        {   
            return(Request.ApplicationPath + "/UpLoads/Photoes/"  + PhotoUrl.Substring(PhotoUrl.LastIndexOf("/"),
                PhotoUrl.Length - PhotoUrl.LastIndexOf("/")));
        }
<asp:ImageButton ID ="Photoes" Width ="130" Height ="100" Runat ="server" CommandName ="Photo" ImageUrl ='<%#FormatPhotoUrl((String)DataBinder.Eval(Container.DataItem,"PhotoUrl"))%>' CommandArgument ='<%# DataBinder.Eval(Container.DataItem,"PhotoID") %>'>
                                                        </asp:ImageButton>
3 回复
#2
bygg2008-11-27 16:47
PhotoUrl.LastIndexOf("/") 这个有可能是 -1
所以在调用它之前应该判断一下.
#3
wangjian_g2008-11-27 19:41
如何让PhotoUrl.LastIndexOf("/")成正值呀
#4
bygg2008-11-28 09:57
public String FormatPhotoUrl(String PhotoUrl)
{   
    if(PhotoUrl.LastIndexOf("/") != -1 && PhotoUrl.LastIndexOf("/") < PhotoUrl.Length)
    {
         return(Request.ApplicationPath + "/UpLoads/Photoes/"  + PhotoUrl.Substring(PhotoUrl.LastIndexOf("/"),
     PhotoUrl.Length - PhotoUrl.LastIndexOf("/")));
     }
     else
     {
          return "";
     }
}
1