Click here to Skip to main content
13,295,472 members (50,832 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads


49 bookmarked
Posted 3 Nov 2008

Display image gallery in ASP.NET GridView Control

, 3 Nov 2008
Here we can use GridView control to display images in a gallery view with internal paging.
Imports System
Imports System.Data
Partial Class gallary
    Inherits System.Web.UI.Page

#Region " Data Members "

    Dim objPropertyForSale As New Propertyforsale

#End Region

#Region " Page Events "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            ''To set page nuber after redirecting back from detail page
            If Request.QueryString("iPn") <> Nothing Or IsNumeric(Request.QueryString("iPn")) Then

                gvListProperty.PageIndex = CInt(Request.QueryString("iPn"))

            End If

            Call BindPropertyGallary()

        End If

    End Sub

    Protected Sub gvListProperty_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvListProperty.PageIndexChanging

        gvListProperty.PageIndex = e.NewPageIndex
        Call BindPropertyGallary()

    End Sub

#End Region

#Region " Functions "

    Public Sub BindPropertyGallary()
        Dim dsProperty As DataSet

        With objPropertyForSale

            '-- For Sale -- link button text binding 
            .AdsCategoryValue = ViewState("AdsCategoryValue")

            dsProperty = .Gallaryview_PropertyList()

            If dsProperty.Tables(0).Rows.Count > 0 Then

                Call DataTableBind(dsProperty)

            End If

        End With

    End Sub

    Public Sub DataTableBind(ByVal dsProperty As DataSet)

        '-- Paging Variables --'
        'Due to Paging Counter == 40 Records per page
        Dim iCountIncre As Integer = 40 ' Records per page
        Dim iPn As Integer = 0 'Current Page Number
        Dim sAds As String
        '-- End Paging Variables --'

        Dim iCount As Integer
        Dim iColumn As Integer = 1

        Dim dtTable As New DataTable
        Dim dtCol As DataColumn
        Dim dtRow As DataRow

        dtCol = New DataColumn("Column1")

        dtCol = New DataColumn("Column2")

        dtCol = New DataColumn("Column3")

        dtCol = New DataColumn("Column4")

        dtRow = dtTable.NewRow

        If ViewState("AdsCategoryValue") = "For sale" Then
            sAds = "s"
        ElseIf ViewState("AdsCategoryValue") = "For rent" Then
            sAds = "r"
        ElseIf ViewState("AdsCategoryValue") = "For Condossale" Then
            sAds = "c"
        End If

        For iCount = 0 To dsProperty.Tables(0).Rows.Count - 1

            If (iCount + 1) > iCountIncre Then
                iCountIncre = iCountIncre + 40
                iPn = iPn + 1
            End If

            dtRow("Column" & iColumn) = "<a  href='fulladdforrent.aspx?sAds=" & sAds & "&iPn=" & iPn.ToString & "&QCD=GLV&QID=" & dsProperty.Tables(0).Rows(iCount).Item("iPropertyID") & "' class='txt-grey'> <img src='../Images/Property/thumb/" & dsProperty.Tables(0).Rows(iCount).Item("sImageName") & "' border='0'  alt='Vis'/>"
            iColumn = iColumn + 1

            If iColumn = 5 Then

                dtRow = dtTable.NewRow

                iColumn = 1

            End If

            If iCount = dsProperty.Tables(0).Rows.Count - 1 And iColumn <= 5 Then
                dtRow = dtTable.NewRow
            End If

        Dim ds As New DataSet


        gvListProperty.DataSource = ds

    End Sub

#End Region

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Vimal Panara
Technical Lead IndiaNIC Infotech Ltd
India India
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 4 Nov 2008
Article Copyright 2008 by Vimal Panara
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid