Paging in .NET without a DataGrid
Again with the paging…
Well, I need it. I’ve spent waaaay to long trying to redesign the mod listing pages and this is what I’ve come up with that seems to work:
<div id=”Content”>
<asp:DataList id=”theDataList” RepeatLayout=”Flow” runat=”server”>
<ItemTemplate>
<div class=”Item”>
<%#BuildItem(DataBinder.Eval(Container.DataItem, “fld1″), DataBinder.Eval(Container.DataItem, “fld2″), Container.ItemIndex)%>
</div>
<%#LineWrap(Container.ItemIndex)%>
</ItemTemplate>
</asp:DataList>
</div>
>script language=”javascript” type=”text/javascript”>stripOutBR(’Content’);</script>
Dim strConn As String = ConfigurationManager.ConnectionStrings(”Database”).ConnectionString
Dim objConn As New System.Data.SqlClient.SqlConnection(strConn)
Dim objCommand As New System.Data.SqlClient.SqlCommand
Dim dsTemp As System.Data.DataSet = New System.Data.DataSet
Dim strSQL As String = “”
objCommand.Connection = objConn
strSQL = “SELECT * FROM table”
Dim objAdapter As New System.Data.SqlClient.SqlDataAdapter(strSQL, objConn)
objAdapter.Fill(dsTemp, “table”)
objConn.Close()
objAdapter.Dispose()
objConn.Dispose()
Dim objDps As PagedDataSource = New PagedDataSource
objDps.DataSource = dsTemp.Tables(0).DefaultView
objDps.AllowPaging = True
objDps.PageSize = 15 ‘ Amount of records to show on each page
theDataList.DataSource = objDps
theDataList.DataBind()
Public Function BuildItem(ByVal fld1 As String, ByVal fld2 As String, ByVal intCount As Integer) As String
…
Format the data to be displayed the way I want
…
End Function
‘ This function is used to throw in a div with style=”clear:both”
‘ to make a new line every 5th object
Public Function LineWrap(ByVal intLineNumber As Integer) As String
Dim strSpacer As String = “”
If intLineNumber = 4 Or intLineNumber = 9 Or intLineNumber = 14 Then
strSpacer = “<div class=”"spacer”"> </div>”
End If
Return strSpacer
End Function
/* this script is to clear out the tags the DataList throws in.
IE 6 doesn’t like them. Just make sure you call it AFTER
the datalist is written out. */
function stripOutBR(theID){document.getElementById(theID).innerHTML = document.getElementById(theID).innerHTML.replace(/<\/span><br><span>/gi,”);}
Then using the various methods of the objDps object (the PagedDataSource) you can set the current page, list out how many items there are, how many pages, etc. Just mess around with it. I’m not saying this is perfect or correct, as I’m still learning. But this is how I do it and it seems to work.
I deserve a little credit bitch!! LoL!!