我有这个代码,只出现描述,我也想出现ID,如:
1 - Easy
2 - Medium
3 - Hard
我的代码是:
Dim objDDL As New Challange.T
Try
FillDropDownListDS(ddlDS, objDDL.SelectResults(CurrentContext.CurrentUserId, CurrentContext.CurrentCulture.idCulture), "desc", "id", True, True)
Catch ex As Exception
Finally
objDDL = Nothing
End Try
ddlDS.DropDown.SelectedValue = ParseDbField(ds.Tables(0).Rows(0), "id" + "desc")
.Tdropdown = ddlDS.DropDown.SelectedValue
Public Sub FillDropDownListDS(ByVal objCombo As DropDownListControl, ByVal DS As DataSet, ByVal TextField As String, ByVal ValueField As String, Optional ByVal BlankRow As Boolean = True, Optional ByVal clear As Boolean = True, Optional ByVal SelectIfUnique As Boolean = False, Optional ByVal SelectOldValue As Boolean = False, Optional ByVal concatValue As String = "")
FillDropDownListDT(objCombo, DS.Tables(0), TextField, ValueField, BlankRow, clear, SelectIfUnique, SelectOldValue, concatValue)
End Sub
FillDropDownListDT:
Dim dr As DataRow
Dim OldValue As String = ""
If Not IsNothing(objCombo) AndAlso objCombo.DropDown.Items.Count > 0 Then
OldValue = objCombo.DropDown.SelectedItem.Value
End If
If clear = True Then
objCombo.DropDown.Items.Clear()
End If
If BlankRow Then
objCombo.DropDown.Items.Insert(0, New ListItem("--Select--", ""))
objCombo.DropDown.SelectedIndex = 0
objCombo.SelectedValue = objCombo.DropDown.SelectedItem.Value
objCombo.SelectedText = objCombo.DropDown.SelectedItem.Text
End If
For Each dr In DT.Rows
Dim lit As New ListItem
lit.Text = ParseDbField(dr, TextField)
If concatValue = "" Then
lit.Value = ParseDbField(dr, ValueField)
Else
lit.Value = ParseDbField(dr, ValueField) & "§" & ParseDbField(dr, concatValue)
End If