我想知道除了以下示例之外是否还有其他方法可以对ajax组合框进行排序;
Public Class ListItemComparer
Implements IComparer(Of ListItem)
Public Function Compare(ByVal x As ListItem, ByVal y As ListItem) As Integer _
Implements IComparer(Of ListItem).Compare
Dim c As New CaseInsensitiveComparer
Return c.Compare(x.Text, y.Text)
End Function
End Class
Public Shared Sub SortDropDown(ByVal cbo As AjaxControlToolkit.ComboBox)
Dim lstListItems As New List(Of ListItem)
For Each li As ListItem In cbo.Items
lstListItems.Add(li)
Next
lstListItems.Sort(New ListItemComparer)
cbo.Items.Clear()
cbo.Items.AddRange(lstListItems.ToArray)
End Sub
----------Binding and Sorting Combo-Box----------
ddlClients.DataTextField = "ClientName"
ddlClients.DataValueField = "ClientID"
ddlClients.DataBind()
SortDropDown(ddlClients)
在SP中,我在客户端名称上使用order by子句,但不知何故,combox没有按顺序绑定ClientNames。
我喜欢将此函数放在CommonFunction类中,以便我可以从项目中的不同位置调用它。我无法在BusinessLayer中添加上述函数,因为'AjaxControlToolkit.ComboBox'