试试这个:
Dim strS As String = ""
Dim dt As DataTable = objDataSet.Tables(1)
' create a lambda expression to split the name by " "
Dim splitName = Function(name As String) name.Split(" "c).Where(Function(s) s <> "")
' select rows that meet the SID filter and SName <> null and SName <> "",
' and get the SID, construct the FirstName and LastName,
' and of course, sort the return collection by LastName
Dim sortedrows = From row As DataRow In dt.Rows
Where (Not IsDBNull(row!SName) AndAlso Not String.IsNullOrWhiteSpace(CStr(row!SName)))
And CStr(row!SID) = strSID
Select PersonID = row!PersonID,
FirstName = splitName(CStr(row!SName)).FirstOrDefault,
LastName = splitName(CStr(row!SName)).LastOrDefault
Order By LastName
' finally, construct the <a> tags as required from above
For Each row In sortedrows
strS &= String.Format("<a href=""javascript: ViewPersonId({0}); return false;"">{1} {2}</a><br />", row.PersonID, row.FirstName, row.LastName)
Next
如果DataTable包含以下行:
dt.Rows.Add(1, "John Travolta")
dt.Rows.Add(2, "Jack The Ripper")
dt.Rows.Add(3, "Beyonce")
dt.Rows.Add(4, " ")
dt.Rows.Add(5, "")
dt.Rows.Add(6, DBNull.Value)
比方说,他们都满足了SID过滤器,它会返回:
<a href="javascript: ViewPersonId(3); return false;">Beyonce Beyonce</a><br />
<a href="javascript: ViewPersonId(2); return false;">Jack Ripper</a><br />
<a href="javascript: ViewPersonId(1); return false;">John Travolta</a><br />
就像你可以看到,"Beyonce"
显示为"Beyonce Beyonce"
。如果您不想要这种行为,可以通过检查For Each
循环中的FirstName = LastName并执行替代代码来构造<a>
标记来更改它。
这不是'ArrayList',它是'DataView'。 – 2013-04-25 17:36:26
好点,编辑。我通过编写问题中途改变了战术。道歉。 – 2013-04-25 17:37:48
我以为你已经问过类似这个问题[这里](http:// stackoverflow。COM /问题/ 15934925 /何灿的i-排序的 - 内容 - Telerik的-gridboundcolumn为主,在-A-子)。你不能应用我给你的同样的方法吗? – ajakblackgoat 2013-04-25 18:26:12