2016-04-28 116 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