Torna al Thread

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %> <%@ Import Namespace="MySql.Data.MySqlClient" %> <%@ Import Namespace="System.IO" %> <script runat="server"> String connectionString = ConfigurationManager.ConnectionStrings["Personal"].ConnectionString; PagedDataSource pg; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) popola(); } void popola() { using (MySqlConnection conn = new MySqlConnection(connectionString)) { string SQL = ""; SQL = SQL + "SELECT * FROM foto WHERE _dirID=@dir"; conn.Open(); MySqlCommand cmd = new MySqlCommand(SQL, conn); cmd.Parameters.AddWithValue("@dir", "" + Request.QueryString["dir"] + ""); MySqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { if (Request.QueryString["dir"] == null) { lblError.Text = ""; btnNext.Visible = false; btnPrev.Visible = false; } else if (Request.QueryString["dir"] == "") { lblError.Text = "non paratemtro dir"; btnNext.Visible = false; btnPrev.Visible = false; } else if (Directory.Exists(Server.MapPath("../public/photo/" + rdr["_dir"] + ""))) { DirectoryInfo dir = new DirectoryInfo(Server.MapPath("../public/photo/" + rdr["_dir"] + "")); FileInfo[] files = dir.GetFiles(); ArrayList list = new ArrayList(); foreach (FileInfo oItem in files) { if (oItem.Extension == ".jpg") list.Add(oItem); } // Create a new PAGED data source and config the settings. pg = new PagedDataSource(); pg.DataSource = list; pg.AllowPaging = true; pg.PageSize = 20; // Move to the appropriate page based on the query string. try { if (Request.QueryString["Page"] == null) { pg.CurrentPageIndex = 0; } else { pg.CurrentPageIndex = Int32.Parse(Request.QueryString["Page"].ToString()); } } catch (Exception ex) { pg.CurrentPageIndex = 0; Response.Write(ex.ToString()); } // Enable and/or disable the previous and next buttons btnPrev.Enabled = !pg.IsFirstPage; btnNext.Enabled = !pg.IsLastPage; // Display which is the current page being displayed lblCurrentPage.Text = "Page: " + (pg.CurrentPageIndex + 1).ToString(); //Bind paged data source to DataList DataList1.DataSource = pg; DataList1.DataBind(); } } else { lblError.Text = "Non esiste"; btnNext.Visible = false; btnPrev.Visible = false; } } } // Return to previous page public void Prev_Click(Object sender, EventArgs e) { Response.Redirect("test_gallery.aspx?dir=" + Request.QueryString["dir"] + "&Page=" + (pg.CurrentPageIndex - 1)); } // Move to next page public void Next_Click(Object sender, EventArgs e) { Response.Redirect("test_gallery.aspx?dir=" + Request.QueryString["dir"] + "&Page=" + (pg.CurrentPageIndex + 1)); } protected void DropDownList1_Init(object sender, EventArgs e) { using (MySqlConnection conn = new MySqlConnection(connectionString)) { string SQL = "SELECT * FROM foto_dir "; conn.Open(); MySqlCommand cmd = new MySqlCommand(SQL, conn); MySqlDataReader ddlValues; ddlValues = cmd.ExecuteReader(); DropDownList1.DataSource = ddlValues; DropDownList1.DataValueField = "ID"; DropDownList1.DataTextField = "_dir"; DropDownList1.DataBind(); conn.Close(); conn.Dispose(); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Response.Redirect("test_gallery.aspx?dir=" + DropDownList1.SelectedItem.Value + ""); } </script> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <p style="background-color:#FFCC00;">Galleria</p> <asp:DropDownList ID="DropDownList1" runat="server" oninit="DropDownList1_Init" autopostback="True" AppendDataBoundItems="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged" > <asp:ListItem Value="Seleziona" Text="Seleziona"></asp:ListItem> </asp:DropDownList> <asp:Label ID="lblError" runat="server" ></asp:Label> <asp:DataList ID="DataList1" runat="server" RepeatColumns="5" CellPadding="5" Width="100%"> <ItemTemplate> <a href="../public/photo/<%# Request.QueryString["dir"] %>/big/<%# Eval("Name") %>"><img src="../public/photo/<%# Request.QueryString["dir"] %>/<%# Eval("Name") %>" width="100%" alt="<%# Eval("Name") %>"/></a> </ItemTemplate> <ItemStyle BorderColor="silver" BorderStyle="dotted" BorderWidth="3px" HorizontalAlign="Center" VerticalAlign="Bottom" /> </asp:DataList><asp:LinkButton id="btnPrev" Text="&lt;&lt; Prev" OnClick="Prev_Click" runat="server"/> <asp:Label id="lblCurrentPage" runat="server"/> <asp:LinkButton id="btnNext" Text="Next &gt;&gt;" OnClick="Next_Click" runat="server"/></asp:Content>
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5