我正在使用带有gridview控件的Hijri Gerogian Datapicker的许多实例,当我从gridview中删除时,会收到以下错误:
StartIndex cannot be less than zero.
Parameter name: startIndex
Line 173: //to manage multiple instances of user control postback, incase the postback happend due to culture changeed in current control,
Line 174: //the other user contrls culture drop down list to be changed accordingly. Also year and month dropdown lists according to culture
Line 175: if (strPostBackControlName != "" && strPostBackControlName.Substring(strPostBackControlName.LastIndexOf("$")) == "$ddlLocaleChoice")
Line 176: {
Line 177: if (ddlLocaleChoice.SelectedValue == arabicCulture.Name)
[ArgumentOutOfRangeException: StartIndex cannot be less than zero.
Parameter name: startIndex]
System.String.Substring(Int32 startIndex, Int32 length) +13011515
System.String.Substring(Int32 startIndex) +15
Hijri_Greg_DatePicker_Sample.HijriGregDatePicker.Page_Load(Object sender, EventArgs e) in C:\Users\Mawni\Desktop\Hijri_Greg_DatePicker_Sample\HijriGregDatePicker.ascx.cs:175
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678
有帮助吗?
答案 0 :(得分:1)
看看这段代码:
strPostBackControlName.LastIndexOf("$")
它将返回字符串中$
的最后一个索引,但是当找不到$
时,它将返回-1
作为结果。稍后,您将尝试使用此结果调用strPostBackControlName.Substring
,但是Substring
具有以下原型:
public string Substring (int startIndex);
您当然不能使用起始索引小于0的名称来调用它(因为字符串中的索引从0
开始)。添加检查以确保LastIndexOf("$")
不是-1
或确保strPostBackControlName
始终包含$
。