我有一个DetailsView,它包含几个文本框和一个DropDownList。如何引用DetailsView中的DropDownList?
现在,我想要做的是为该DropDownList编写SelectedIndexChanged事件,但我的问题是我无法再达到/引用它。
如果我只是在窗体上放置一个DropDownList,它没有问题,但现在它是在DetailsView中看起来不可能达到它。
有什么建议吗?
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Protected Sub DetailsViewAvtaleInfo_PageIndexChanging1(sender As Object, e As DetailsViewPageEventArgs) Handles DetailsViewAvtaleInfo.PageIndexChanging
Dim DropDownListContractType As DropDownList = DirectCast(Me.DetailsViewAvtaleInfo.FindControl("DropDownListContractType"), DropDownList)
Dim TextBoxLeasingPriceMonth As TextBox = DirectCast(Me.DetailsViewAvtaleInfo.FindControl("TextBoxLeasingPriceMonth"), TextBox)
If DropDownListContractType.Text = "Kjøp" Then
TextBoxLeasingPriceMonth.Visible = False
End If
End Sub
我知道这是不对的,但它就我所知。我希望只写以下子中的代码,但它只是将不起作用:
Protected Sub DropDownListContractType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownListContractType.SelectedIndexChanged
Dim TextBoxLeasingPriceMonth As TextBox = DirectCast(Me.DetailsViewAvtaleInfo.FindControl("TextBoxLeasingPriceMonth"), TextBox)
If DropDownListContractType.Text = "Leasing" Then
TextBoxLeasingPriceMonth.Visible = False
End If
End Sub
“...但它不会工作” - 更具体。它在第一段代码中看到了你的Dropdown还是仅在第二段?为什么不使用FindControl()来获取下拉菜单? – 2014-01-26 01:01:15