在ASP.NET中,我有一個dropdown
,其中有一些項目,我有button
和textbox
。我訂閱了下拉菜單的SelectedIndexChanged
事件,其中我將下拉的新選定索引傳遞給將其索引(通過enum
)轉換爲字符串的結構。該字符串然後通過類中的一個屬性獲取到文本框中。通過列表框中的選定項目更新文本框
//Enum and struct representing index to string conversion for dropdown
Public Enum e_action
AcOne = 0
AcTwo
AcThree
AcThree
AcFour
End Enum
Public Structure Action
Public Sub New(ByVal index As Integer)
Select Case index
Case 0
action = e_action.AcOne
Case 1
action = e_action.AcTwo
Case 2
action = e_action.AcThree
Case 3
action = e_action.AcFour
Case 4
action = e_action.AcFive
End Select
End Sub
//這是在下拉菜單中的SelectedIndexChanged功能
Protected Sub dropdownAction_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dropdownAction.SelectedIndexChanged
Dim ddl As DropDownList = TryCast(sender, DropDownList)
If Not IsNothing(ddl) Then
Dim act As New Action(ddl.SelectedIndex)
p_two_action = act //p_two_action is a global var of type Action
End If
End Sub
//inside the button handler
dim myclass as MyClass
MyTextBox.Text = myclass.getAction //returns string of action done in dropdown
現在我的問題是,當你點擊它(按鈕)第一次,動作獲取與更新在列表框中選擇當前動作,但是當你再次單擊該按鈕時沒有更改列表框中的任何內容,文本框顯示文本框中的第零項(似乎重置),儘管它實際上並未在所有。
我猜這可能與按鈕點擊引起的回發有關,這會重置全局狀態或某些內容,但我不確定。爲什麼當下拉框仍然是我第一次設置時它被重置?
有人可以幫忙嗎?
如果這不清楚,請留下評論什麼是不明確的。謝謝!
你有沒有在Page_Load事件中運行的任何代碼?您是否嘗試在click事件中運行帶有斷點的調試器,以查看myclass.getAction在第二次調用中返回的內容? – 2011-03-11 23:07:05
@Zach我真的很想調試它,但我不能。項目在遠程計算機上... – 2011-03-11 23:13:50
使用值加載所有下拉框的函數位於頁面加載函數中...也許這是導致問題的原因? – 2011-03-11 23:14:24