我正在用這個拉出我的頭髮。FinByValue在UserControl的上下文中不起作用DropDownList
我有一個員工dropdownlist usercontrol(uxEmployee),我已經公開SelectedValue方法作爲屬性(SelectedValue)。
在我的頁面我想要根據我的數據設置值或將值添加到列表中,如果它目前不在那裏。
無論我做什麼,它都將設置值添加到列表中。即使該值已經在列表中,它仍然在增加價值。無論我做什麼,基本上FindByValue總是返回「Nothing」。任何幫助,將不勝感激。
Public Property SelectedValue() As String
Get
Return uxEmployee.SelectedValue
End Get
Set(ByVal value As String)
If Not uxEmployee.Items.FindByValue(value) Is Nothing Then
uxEmployee.SelectedValue = value
Else
uxEmployee.Items.Insert(0, New ListItem(value, value))
uxEmployee.AppendDataBoundItems = True
uxEmployee.DataBind()
End If
End Set
End Property
Public WriteOnly Property Department() As String
Set(ByVal value As String)
_department = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not (IsPostBack) Then
Dim emp As New Employee()
With uxEmployee
If _department <> String.Empty Then
.DataSource = emp.GetByDept(_department)
Else
.DataSource = emp.GetList()
End If
.DataTextField = "FullName"
.DataValueField = "UserName"
.DataBind()
End With
End If
End Sub
我的調用頁使用以下在頁面加載.. uxSalesleadv是uxemployee
Dim objPrj As ServiceProject = New ServiceProject()
objPrj = objPrj.GetItem(prjID)
With objPrj
uxSalesLead.SelectedValue = .SalesLead
End With
你最初如何填充uxEmployee.Items? – 2011-03-23 23:11:08
我的GetList函數只返回一個reguluar業務對象類的數據集。 – jsam 2011-03-24 04:47:48
是否可以在dropdownlist usercontrol的SET屬性中使用getselectedvalue?任何人可以協助? – jsam 2011-03-24 06:39:10