在DropDownList中,我添加了屬性,即添加列表項時的abcd。DropDownList SelectedItem屬性總數總是返回0
它在HTML頁面呈現後出現,當我嘗試在回發它不存在後在.cs文件中訪問它時。
ddl.SelectedItem.Attribute的數量總是返回0
我怎樣才能做到這一點。
的屬性值應該是布爾(1,0將被罰款)
以下是代碼將數據綁定到DDL不會被髮送回服務器
Private Sub LoadSetTypes()
SetTypes.Items.Clear()
Dim setTypesList As List(Of Entities.Sets.SetType) = Config.SetMetaData.GetSetTypes(setInformation)
SetTypes.DataTextField = "SetTypeName"
SetTypes.DataValueField = "SetTypeID"
SetTypes.DataSource = setTypesList
SetTypes.DataBind()
SetTypesUpdatePanel.Update()
Dim i As Int32 = 0
'For Each setType As Entities.Sets.SetType In setTypesList
For Each lm As ListItem In SetTypes.Items
Dim setType As Entities.Sets.SetType = setTypesList(i)
i = i + 1
'Dim listItem As ListItem = New ListItem(setType.SetTypeName, setType.SetTypeID)
If (setType.IsProfiled) Then
lm.Attributes.Add("IsProfiled", "1")
End If
'SetTypes.Items.Add(listItem)
Next
SetTypes.SelectedValue = Nothing
SetTypes.Items.Insert(0, "Please Choose")
SetTypes.SelectedValue = 0
SetTypesUpdatePanel.Update()
End Sub
自定義屬性不會在回發中保留;在'ViewState'中默認。 http://www.4guysfromrolla.com/articles/110205-1.aspx –
將您的代碼放在這裏 –
自定義屬性不會在回傳中持久化 - 所以您可以嘗試擴展控件並覆蓋SaveViewState方法以將其存儲在視圖狀態。 – NoviceProgrammer