Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PhotoViewer.aspx.cs" Inherits="PhotViewer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

    <script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>

    <script src="Scripts/jquery.lightbox-0.5.js" type="text/javascript"></script>

    <link href="css/jqu<big></big>ery.lightbox-0.5.css" rel="stylesheet" type="text/css" />

    
    <script type="text/javascript">
        $(function () {
            $('#images  a').lightBox({ fixedNavigation: true });

        });
    </script>
<%--<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,slider"></script>
<script type="text/javascript" src="js/lightview.js"></script>
<link rel="stylesheet" href="lightview.css" type="text/css" media="screen" />
--%></head>
<body>
 <a href ="Images/13.jpg" ><asp:Image ID="Image1" Height="50%" Width ="50%" runat="server"/></a>

    <form id="form1" runat="server">
    <table>
    <tr>
    <td>

        <asp:ListView ID="lvPhotoViewer" runat="server" GroupItemCount="1">
         <LayoutTemplate>
             <table ID="groupPlaceholderContainer" runat="server" border="1">
                  <tr ID="groupPlaceholder" runat="server">
                  </tr>
             </table>
         </LayoutTemplate>

         <ItemTemplate>
             <td id="Td4" align="center" style="background-color: #eeeeee;">
             <div id="images">

                    <a href='<%# Eval("Photo") %>' >
                    <asp:Image runat="server" ID="imPhoto" Height="450px" Width="450px" ImageUrl='<%# "~"+Eval("Photo") %>'  />
                    </a><br />
                    <asp:Label ID="DefaultPhotIDLabel" runat="server"
                            Text='<%# Eval("PhotoName") %>' />
                            </div>
             </td>
        </ItemTemplate>

         <GroupTemplate>
              <tr ID="itemPlaceholderContainer" runat="server">
                   <td ID="itemPlaceholder" runat="server">
                   </td>
              </tr>
        </GroupTemplate>
        </asp:ListView>

    </td>
    </tr>
    <tr>
    <td align="center">
        <asp:DataPager ID="DataPager1" runat="server"
        PagedControlID="lvPhotoViewer" PageSize="1"
        onprerender="DataPager1_PreRender">
        <Fields>
            <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="true" ShowPreviousPageButton="true"
             ShowLastPageButton="True" ShowNextPageButton="true"
            PreviousPageText="<< " NextPageText=">>" />
         </Fields>
        </asp:DataPager>
    </td>
    </tr>
    </table>

    </form>
</body>
</html>







code behind


protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string photoID = Request.QueryString["PhotoID"];
            string albumID = Request.QueryString["AlbumID"];
            ViewState["hfAlbumID"] = albumID;
            //Get Page number by passing photo id
            int index = GetPageNumber(int.Parse(photoID), int.Parse(albumID));
            DataPager1.SetPageProperties(index, 1, true);

        }
    }
    /// <summary>
    /// Since the pagesize is 1 the row number can be taken as page number
    /// </summary>
    /// <param name="PhotoID"></param>
    /// <param name="AlbumID"></param>
    /// <returns></returns>
    public int GetPageNumber(int PhotoID,int AlbumID)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        con.Open();
        SqlCommand com = new SqlCommand("SELECT PageNumber FROM (SELECT row_number() Over (order by photoid asc) AS PageNumber,photoid,Albumid FROM PhotAlbum where Albumid=" + AlbumID.ToString() + ") As Photos where photoid=" + PhotoID.ToString() + " and Albumid=" + AlbumID.ToString(), con);
        SqlDataReader dr = com.ExecuteReader();
        int pageno = 1;
        if (dr.Read())
        {
            pageno = int.Parse(dr["PageNumber"].ToString());
        }
        dr.Close();
        con.Close();
        return (pageno - 1);
    }
    public DataTable GetPhoto(string query)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlDataAdapter ada = new SqlDataAdapter(query, con);
        DataTable dtEmp = new DataTable();
        ada.Fill(dtEmp);
        return dtEmp;
    }
    protected void DataPager1_PreRender(object sender, EventArgs e)
    {
        lvPhotoViewer.DataSource = GetPhoto("Select * from PhotAlbum where AlbumID = " + ViewState["hfAlbumID"].ToString());
        lvPhotoViewer.DataBind();
    }
}
Posted
Updated 11-Mar-13 4:35am
v2
Comments
Prasad Khandekar 11-Mar-13 10:33am    
Hello,

What problem(s) are you facing with the current code?
Prasad Khandekar 11-Mar-13 10:38am    
Hello,

Found a nice sample to display images in a web page at http://www.dotnetcurry.com/ShowArticle.aspx?ID=175.
ghincelino 12-Mar-13 23:21pm    
try to debug your code to find the problem..

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900