Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using facebox on my asp.net web site for my image gallery. when i am uploading images to the gallery, they are saved on my disc and url data is stored in my sql database. After the uploading, my gallery displays thumbnails from the images but not in the order as they are uploaded. I want to display the last uploaded image as first in the gallery (order by last uploaded), but i don't know what i should add in the code.

This is the code:


<body style="background-color:black">
 <script type="text/javascript" charset="utf-8">
     $(function () {
         $('[rel^="FaceBox"]').FaceBox();
     });
    </script>
<form id="form1" runat="server">
  <div class="Znamenitosti" id="Znamenitosti">
         <asp:DataList ID="dlImages" runat="server" RepeatColumns="7" CellPadding="3"  >
 <ItemTemplate>
<div class="boxButton">
<ul class="Gallery" >
 <li><a id="A1"   href='<%# Eval("ime","~/Sliki/Ohrid/Znamenitosti/{0}") %>' title='<%#   "Од "+ Eval("userid")+ ", на " +  Eval("datum")+ ", " +  Eval("opis")%>'  rel="FaceBox[gallery1]"   runat="server" >
 <asp:Image ID="Image1"  ImageUrl='<%# Bind("imethumb",  "~/Sliki/Ohrid/Znamenitosti/thumb/{0}") %>' runat="server" Width="140" Height="140" AlternateText='<%# Bind("imeslika") %>' />
 </a></li></ul></div>
 </ItemTemplate>
 </asp:DataList>
 </div>


Cs code:

 protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack)
    {

        BindDataList();


    }

}     
   protected void BindDataList()
{
    String strConnString = System.Configuration.ConfigurationManager
        .ConnectionStrings["makbazaConnectionString"].ConnectionString;
    SqlConnection con = new SqlConnection(strConnString);
    con.Open();
    if (Request.QueryString["ID"] == "Znamenitosti")
    {
        //Query to get ImagesName and Description from database

        SqlCommand command = new SqlCommand("SELECT ime, imethumb, imeslika, kategorija, datum, opis, slikapateka, thumbpateka, userid FROM Ohrid WHERE kategorija='Znamenitosti' AND grad='Ohrid' ", con);
        SqlDataAdapter da = new SqlDataAdapter(command);
        DataTable dt = new DataTable();
        da.Fill(dt);
        dlImages.DataSource = dt;
        dlImages.DataBind();
    }
    .
    .
    .
    .
    con.Close();
}
Posted
Comments
[no name] 15-Sep-13 15:41pm    
Looks like you would need to add an ORDER BY clause to your query.
CHill60 15-Sep-13 15:42pm    
"order by lastuploaded" is exactly what you need, but I'm guessing that you don't have a "lastuploaded" column on your Ohrid table. You could create such a column (datetime) and have a SQL Trigger automatically update it when you insert a new record - there is an example here http://stackoverflow.com/questions/7349288/how-do-i-add-a-last-updated-column-in-a-sql-server-2008-r2-table[^]

1 solution

step 1: I would suggest you to add a uploaddatetime field to your table and capture the uploaded datetime against all the images.

step 2: In your select query :
"SELECT ime, imethumb, imeslika, kategorija, datum, opis, slikapateka, thumbpateka, userid FROM Ohrid WHERE kategorija='Znamenitosti' AND grad='Ohrid' " add an order by uploaddatetime desc.

your query becomes

SELECT ime, imethumb, imeslika, kategorija, datum, opis, slikapateka, thumbpateka, userid FROM Ohrid WHERE kategorija='Znamenitosti' AND grad='Ohrid' ORDER BY UploadDateTime DESC
 
Share this answer
 

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