我有一个奇怪的问题,下拉框 selectedIndex 在回发时总是设置为 0。我不会不小心在我的代码中重新绑定它。事实上,我已经在 page_load 事件的第一行放置了一个断点,并且该值已经设置为零。下拉列表在我的项目的母版页中,我不知道这是否会有所不同。我没有在我的内容持有者中引用控件。
如果我设置我的 autoPostBack = 'true' 页面工作正常。我不必更改任何代码,并且 selectedIndex 会被维护。我也尝试过设置 enableViewState on 和 off 并没有什么区别。在这一点上,我正在抓住稻草来弄清楚发生了什么。我以前从来没有遇到过这个问题。
这是我的 page_load 事件中的代码。
If CartEstablished Then
txtCustNum.Visible = False
btnCustSearch.Visible = False
lblCustNum.Visible = True
ddlSalesType.Visible = False
lblSalesType.Visible = True
ddlTerms.Visible = False
lblTerms.Visible = True
lblTerms.Text = TermsDescription
Else
txtCustNum.Visible = True
btnCustSearch.Visible = True
lblCustNum.Visible = False
lblSalesType.Visible = False
ddlSalesType.Visible = True
lblTerms.Visible = False
ddlTerms.Visible = True
End If
If Page.IsPostBack Then
GetUIValues()
Else
LoadTermCodes()
End If
LoadTermCodes 是我绑定导致我出现问题的下拉列表的地方。