System.StackOverflowException触发DataBind()代码时

时间:2016-04-28 20:53:03

标签: asp.net vb.net

我有两个下拉列表,一个正在工作,一个没有完全相同的代码。

正常工作的第一个在TRY中有一个ddlist.databind(),当被触发时,每次运行databind()代码时都不会导致返回到代码开头的无限循环。再一次,这个按照我想要的方式工作。每次databind()发生时,在dropdownlist3上,它会在Sub的开头重新启动代码

Dropdownlist1(正常工作)代码

Protected Sub DropDownlist1_DataBinding1(sender As Object, e As EventArgs)

    Dim O1IDText As String = DirectCast(FindControlRecursive(Me.Page, "HFO1ID"), HiddenField).Value
    Dim ddList As DropDownList = CType(sender, DropDownList)

    RemoveHandler ddList.DataBinding, AddressOf DropDownlist1_DataBinding1
    Dim li As New ListItem("REMOVE / NO Official Scheduled", "", True)
    Dim li3 As New ListItem("▲▲▲▲ Current Selected Official ▲▲▲▲", "", True)
    Dim li4 As New ListItem("▼▼▼▼ All Available Officials ▼▼▼▼", "", True)


    Dim i As Integer = 0

    Try
        ddList.DataBind()

    Catch ex As ArgumentOutOfRangeException

Dropdownlist3(无法正常工作)代码背后:

Protected Sub DropDownlist3_DataBinding3(sender As Object, e As EventArgs)

    Dim O2IDText As String = DirectCast(FindControlRecursive(Me.Page, "HFO2ID"), HiddenField).Value
    Dim ddList As DropDownList = CType(sender, DropDownList)

    RemoveHandler ddList.DataBinding, AddressOf DropDownlist1_DataBinding1
    Dim li As New ListItem("REMOVE / NO Official Scheduled", "", True)
    Dim li3 As New ListItem("▲▲▲▲ Current Selected Official ▲▲▲▲", "", True)
    Dim li4 As New ListItem("▼▼▼▼ All Available Officials ▼▼▼▼", "", True)

    Dim i As Integer = 0

    Try
            ddList.DataBind()

        Catch ex As ArgumentOutOfRangeException

我无法弄清楚为什么一个人做无限循环而另一个没有。

这是每个下拉列表的asp代码:

Dropdownlist1:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostback="True" OnDataBinding="DropDownlist1_DataBinding1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AppendDataBoundItems="True" DataSourceID="SqlDataSource2" DataTextField="FullName" DataValueField="FullName" Height="24px" Width="193px" SelectedValue='<%# Bind("Official1") %>' >

DropDownlist3:

<asp:DropDownList ID="DropDownList3" runat="server" AutoPostback="True" OnDataBinding="DropDownlist3_DataBinding3" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" AppendDataBoundItems="True" DataSourceID="SqlDataSource2" DataTextField="FullName" DataValueField="FullName" Height="25px" SelectedValue='<%# Bind("Official2") %>' Width="203px">

1 个答案:

答案 0 :(得分:2)

我想出了自己的问题

我从未改变结局:

RemoveHandler ddList.DataBinding, AddressOf DropDownlist1_DataBinding1

我需要将此行更改为:

RemoveHandler ddList.DataBinding, AddressOf DropDownlist3_DataBinding3