1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace mon_site
{
public partial class recherche_job : System.Web.UI.Page
{
static string chaine_connexion = ConfigurationManager.ConnectionStrings["Mon_site_ConnectionString"].ToString();
SqlConnection con = new SqlConnection(chaine_connexion);
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
Page.Title = "Recherche de jobs étudiants";
ItemsGet();
}
else
{
Page.Title = "Login nécessaire";
FormsAuthentication.RedirectToLoginPage();
}
}
//Pour la pagination du datarepeater
public int CurrentPage
{
get
{
// look for current page in ViewState
object o = this.ViewState["_CurrentPage"];
if (o == null)
return 0; // default to showing the first page
else
return (int)o;
}
set
{
this.ViewState["_CurrentPage"] = value;
}
}
private void ItemsGet()
{
SqlDataAdapter adapter_jobs = new SqlDataAdapter();
con.Open();
cmd = new SqlCommand(SqlDS_Jobs.SelectCommand.ToString(), con);
adapter_jobs.SelectCommand = cmd;
DataSet ds_jobs = new DataSet();
adapter_jobs.Fill(ds_jobs);
con.Close();
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds_jobs.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 5;
objPds.CurrentPageIndex = CurrentPage;
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " sur " + objPds.PageCount.ToString();
//Rends les boutons "<<" et ">>" disabled si nécessaire
cmdPrev.Enabled = !objPds.IsFirstPage;
cmdNext.Enabled = !objPds.IsLastPage;
Repeater_job.DataSource = objPds;
Repeater_job.DataBind();
}
protected void cmdNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
ItemsGet();
}
protected void cmdPrev_Click(object sender, EventArgs e)
{
CurrentPage -= 1;
ItemsGet();
}
}
} |
Partager