我正在创建一个自定义复选框控件以在复选框列表中的每个复选框之后添加一个 div。课程如下。
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Globalization
Public Class MyCheckboxListCheckBox
Inherits CheckBoxList
Implements IRepeatInfoUser
Protected Overrides Sub RenderItem(ByVal itemType As ListItemType, ByVal repeatIndex As Integer, ByVal repeatInfo As RepeatInfo, ByVal writer As HtmlTextWriter)
writer.WriteBeginTag("input")
writer.WriteAttribute("type", "checkbox")
writer.WriteAttribute("name", UniqueID)
writer.WriteAttribute("id", (ClientID & "_") + repeatIndex.ToString(NumberFormatInfo.InvariantInfo))
writer.WriteAttribute("value", Items(repeatIndex).Value)
Dim attrs As System.Web.UI.AttributeCollection = Items(repeatIndex).Attributes
For Each key As String In attrs.Keys
writer.WriteAttribute(key, attrs(key))
Next
writer.Write(">")
writer.Write(Items(repeatIndex).Text)
' writer.Write("<div id=" & "mynewDiv" & Items(repeatIndex).Value & "></div>")
End Sub
End Class
但是当我在页面中使用它并调用保存时出现错误。错误是:
startIndex 不能大于字符串的长度。参数名称:startIndex 描述:当前Web请求执行过程中发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.ArgumentOutOfRangeException:startIndex 不能大于字符串的长度。参数名称:startIndex
源错误:
在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。
堆栈跟踪:
[ArgumentOutOfRangeException: startIndex 不能大于字符串的长度。参数名称:startIndex]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +7492915
System.Web.UI.WebControls.CheckBoxList.LoadPostData(String postDataKey, NameValueCollection postCollection) +60
System.Web.UI.WebControls。 CheckBoxList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +13
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +346
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint , 布尔型 includeStagesAfterAsyncPoint) +1743
有任何想法吗 ?