0
我試圖用很多方式對列表進行排序,但沒有一個適合我。我一定做錯了什麼。我想對列表details
進行排序,然後將其序列化並將其發送到UI,以便在UI中有一個排序列表。 所以基本上我想Return strJson
返回排序(按排序屬性排序)列表。希望我有道理。如何對列表進行排序?
<WebMethod(Description:="Get Home Page Items Page Wise", EnableSession:=True)> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
Public Function GetHomePageItemsPageWise(ByVal pageIndex As String) As Object
Dim details As New List(Of HomePageObject)()
Dim idObject As New List(Of GetIdBasedOnInterest)()
idObject = CType(BLL.GetDataByInterests(CType(BLL.GetAccIdFromSocialAuthSession(), Integer)), List(Of GetIdBasedOnInterest))
Dim cmd As DbCommand = _db.GetStoredProcCommand("GetHomePageObjectPageWise")
_db.AddInParameter(cmd, "PageIndex", SqlDbType.VarChar, pageIndex)
_db.AddInParameter(cmd, "PageSize", SqlDbType.Int, 10)
_db.AddOutParameter(cmd, "PageCount", SqlDbType.Int, 1)
_db.AddInParameter(cmd, "whereStoryID", SqlDbType.VarChar, idObject(0).StoryIds)
_db.AddInParameter(cmd, "whereAlbumID", SqlDbType.VarChar, idObject(0).AlbumIds)
_db.AddInParameter(cmd, "wherePictureID", SqlDbType.VarChar, idObject(0).PictureIds)
Try
Using ds As DataSet = _db.ExecuteDataSet(cmd)
For Each rs As DataRow In ds.Tables(0).Rows
Dim homePageObject As New HomePageObject()
homePageObject.AlbumId = rs("AlbumId").ToString()
homePageObject.StoryTitle = rs("StoryTitle").ToString()
homePageObject.AlbumName = rs("AlbumName").ToString()
homePageObject.AlbumCover = rs("AlbumCover").ToString()
homePageObject.Votes = rs("Votes").ToString()
homePageObject.PictureId = rs("PictureId").ToString()
homePageObject.TableName = rs("tableName").ToString()
homePageObject.PageCount = CType(cmd.Parameters("@PageCount").Value, Integer)
homePageObject.Sort = Guid.NewGuid()
details.Add(homePageObject)
Next
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim js As New JavaScriptSerializer()
Dim strJson As String = js.Serialize(details.ToArray)
Return strJson
End Function
可能重複http://stackoverflow.com/questions/3163922/sort-a- custom-class-list) – David
sort屬性是一個GUID,在這裏它似乎毫無用處。 –
@KundanSinghChouhan請解釋一下,你爲什麼說它沒用?我是編程新手。 – user1593175