AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Need Help Adding Paging to Datalist
Posted by sao xiong on  6/7/2010 1:51:30 PM Category: VB.NET
Add to my favorites
Email to friend
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'1. Get list of images
Dim dirInfo As New DirectoryInfo(Server.MapPath(""))
Dim images() As FileInfo = FilterForImages(dirInfo.GetFiles())

'2. Determine the current image to show
Dim imageRnd As New Random()

'3. returns a random image to show between min-index & max-index - new line also - do not change
Dim imgIndex As Integer = imageRnd.Next(0, maxValue:=(images.Length))

'4. randomizing when 'N' is nothing or set to default.aspx
If Not Request.QueryString("N") Is Nothing AndAlso IsNumeric(Request.QueryString("N")) Then
imgIndex = CInt(Request.QueryString("N"))
End If

'5. set image title & count
currentImgTitle.Text = "Saib Duab: " & _
Path.GetFileNameWithoutExtension(images(imgIndex).Name) & _
" (" & imgIndex + 1 & " of " & images.Length & ")"
'6. image to display
currentImg.ImageUrl = Path.GetFileName(images(imgIndex).Name)


'7. display current notes onload and when click with requested image - no change needed
If Not Page.IsPostBack Then
currentImageNotes.Text = currentNotes("")
End If

'do not change from here below
'8. sets previous current image -1
If imgIndex > 0 Then
lnkPrev.NavigateUrl = "testdatalistpaging.aspx?N=" & imgIndex - 1
lnkPrev.ImageUrl = "/pt/resources/navigation/wpreviousdouble.png"
End If

'9. set next current image +1
If imgIndex < images.Length - 1 Then
lnkNext.NavigateUrl = "testdatalistpaging.aspx?N=" & imgIndex + 1
lnkNext.ImageUrl = "/pt/resources/navigation/wnextdouble.png"
End If

'testing paging
totalRecord.Text = "Total Photos from Laos: " & images.Length


'bind to datalist
Datalist1.DataSource = images
Datalist1.DataBind()

End Sub


'binds image to DataBind List - do not change
Sub dlIndex_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then ' was ListItemType.alternativeItem

'call the Hyperlink id from html document page
Dim hl As HyperLink = CType(e.Item.FindControl("lnkPic"), HyperLink)


'sets navigation url
hl.NavigateUrl = "testdatalistpaging.aspx?N=" & e.Item.ItemIndex

End If
End Sub


'here is datalist footer template for paging

<FooterTemplate>

<asp:Label ID="totalRecord" runat="server" Text="totalRecords"></asp:Label>

<asp:LinkButton ID="prev" runat="server"><< Previous</asp:LinkButton>

<asp:LinkButton ID="next" runat="server">Next >></asp:LinkButton>

</FooterTemplate>


Please help!

Post Your Reply Post New Question

 Viewer's Reply
DataList Paging with PagedDataSource object
Answered By Moderator1 on 6/8/2010 8:55:27 AM
Hi,

Read the article in the below url

http://www.aspdotnetcodes.com/DataList_Dynamic_Paging_PagedDataSource.aspx

Please let me know, if you find any problem in using the above article.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Web Application Security — How to Minimize Prevalent Risk of Attacks
Oracle Magazine
Take Advantage of Oracle's 2 Day DBA Course