2016-04-28 25 views
2

我有两个下拉列表一个工作,一个不是完全相同的代码。System.StackOverflowException当DataBind()代码被触发

正确工作的第一个在TRY中有一个ddlist.databind(),当被触发时不会导致无限循环返回到每次数据绑定()代码被触发时的代码开始。再次,这是我想要的方式工作。在dropdownlist3每次数据绑定()情况将重新启动代码在小组

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"> 

回答

2

我想通了,我自己的问题

我从来没有改变结尾:

RemoveHandler ddList.DataBinding, AddressOf DropDownlist1_DataBinding1 

我需要这一行更改为:

RemoveHandler ddList.DataBinding, AddressOf DropDownlist3_DataBinding3