ok guys here is what i got. i got a big image on top to display small thumbnail at the bottom. and these small thumbnail are displayed in datalist. everytime u click on an item it changes the big image to the one u just click on. i got that to work but as soon as i want to do the paging on the datalist, it will work for the first four but then it keeps reseting my id on the thumbnail so i never get passed the first four. and it always reload the page. here is my code maybe u guys can help me with it. if you create new website and copy this in it will work. u just need to have some images in a folder call images inside ur webproject. anycode that i commented out in the default.aspx.vb is because i was trying to do the paging. please help. thank you
default.aspx
default.aspx.vbCode:<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" EnableEventValidation="false" %> <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <HTML> <HEAD> <STYLE TYPE="text/css"> body { font-family:Verdana;font-size: medium;} .ImageTitle { font-weight:bold; font-size:large;} .index {font-size: small;} .NavLink { background-color: yellow; font-weight: bold; } </STYLE> </HEAD> <BODY> <form runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label runat="server" id="currentImgTitle" CssClass="ImageTitle" /><br /> <asp:Image runat="server" id="currentImg" /> <asp:Button ID="cmdPrev" runat="server" Text="Previous" /> <asp:Button ID="cmdNext" runat="server" Text="Next" /> <asp:Button ID="cmdPrev2" runat="server" Text="Previous" /> <p> <asp:DataList runat="server" id="dlIndex" OnItemDataBound="dlIndex_ItemDataBound" RepeatColumns="4" CssClass="index"> <ItemTemplate> <asp:ImageButton runat="server" id="lnkPic" width="50" Height="50" PostBackUrl="Default.aspx?N=5" /> </ItemTemplate> </asp:DataList> <asp:Button ID="cmdNext2" runat="server" Text="Next" /> </ContentTemplate> </asp:UpdatePanel> </form> </BODY> </HTML>
Code:Imports System.IO Partial Class _Default Inherits System.Web.UI.Page Public PageNumber As Integer Function FilterForImages(ByVal images() As FileInfo) As FileInfo() Dim newImages As New ArrayList(images.Length) Dim i As Integer For i = 0 To images.Length - 1 If Path.GetExtension(images(i).Name.ToLower()) = ".jpg" OrElse _ Path.GetExtension(images(i).Name.ToLower()) = ".jpeg" OrElse _ Path.GetExtension(images(i).Name.ToLower()) = ".png" OrElse _ Path.GetExtension(images(i).Name.ToLower()) = ".gif" Then newImages.Add(images(i)) End If Next Return CType(newImages.ToArray(GetType(FileInfo)), FileInfo()) End Function Private Sub LoadDataList() Dim dirInfo As New DirectoryInfo("C:\SlideShow\images") Dim images() As FileInfo = FilterForImages(dirInfo.GetFiles()) Dim imgIndex As Integer = 0 If Not Request.QueryString("N") Is Nothing AndAlso IsNumeric(Request.QueryString("N")) Then imgIndex = CInt(Request.QueryString("N")) End If currentImgTitle.Text = "You are Viewing: " & _ Path.GetFileNameWithoutExtension(images(imgIndex).Name) & _ " (" & imgIndex + 1 & " of " & images.Length & ")" currentImg.ImageUrl = "~/images/" & images(imgIndex).Name If imgIndex > 0 Then cmdPrev.PostBackUrl = "Default.aspx?N=" & imgIndex - 1 End If If imgIndex < images.Length - 1 Then cmdNext.PostBackUrl = "Default.aspx?N=" & imgIndex + 1 End If dlIndex.DataSource = images dlIndex.DataBind() 'Dim objPds As New PagedDataSource 'objPds.DataSource = images 'objPds.AllowPaging = True 'objPds.PageSize = 4 'PageNumber = currentpage() 'objPds.CurrentPageIndex = PageNumber 'dlIndex.DataSource = objPds 'dlIndex.DataBind() End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'If Not Page.IsPostBack Then 'ViewState("Start") = 0 LoadDataList() 'End If End Sub 'Public Function currentpage() As Integer ' Dim obj As New Object ' obj = Me.ViewState("_CurrentPage") ' If obj Is DBNull.Value Then ' Return 0 ' Else ' Return obj ' End If 'End Function 'Protected Sub cmdPrev2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPrev.Click ' 'PageNumber -= 1 ' ViewState("_CurrentPage") = CInt(ViewState("_CurrentPage")) - 1 ' LoadDataList() 'End Sub 'Protected Sub cmdNext2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdNext.Click ' 'PageNumber += 1 ' ViewState("_CurrentPage") = CInt(ViewState("_CurrentPage")) + 1 ' LoadDataList() 'End Sub Protected Sub dlIndex_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlIndex.ItemDataBound If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then Dim h1 As ImageButton = CType(e.Item.FindControl("lnkPic"), ImageButton) h1.ImageUrl = "~/images/" & DataBinder.Eval(e.Item.DataItem, "Name".ToString) h1.PostBackUrl = "Default.aspx?N=" & e.Item.ItemIndex End If End Sub End Class


Reply With Quote