Je travaille par MICROSOFT VISUAL STUDIO.NET 2003 à mon avis c'est asp.net 1
Et voici mon code :
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
namespace
WebApplication2
{
///
<summary>
///
</summary>
public
class WebForm3 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlCommand cmdNext;
protected System.Data.SqlClient.SqlCommand cmdPrevious;
protected System.Web.UI.WebControls.LinkButton btnPrevious;
protected System.Web.UI.WebControls.LinkButton btnNext;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.SqlClient.SqlCommand sqlCommand1;
private
int CurrentPage;
private
void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
CurrentPage = 0;
cmdNext.Parameters["@customerid"].Value = "";
FillGrid(cmdNext);
}
}
private
void FillGrid(System.Data.SqlClient.SqlCommand currentSqlCommand)
{
System.Data.SqlClient.SqlDataReader dr;
sqlConnection1.Open();
dr = currentSqlCommand.ExecuteReader();
DataGrid1.DataSource = dr;
DataGrid1.DataBind();
dr.Close();
sqlConnection1.Close();
ViewState["CurrentPage"] = CurrentPage;
ViewState[CurrentPage.ToString()] = DataGrid1.Items[0].Cells[0].Text;
if (DataGrid1.Items.Count < DataGrid1.PageSize)
{
btnNext.Enabled = false;
}
}
private
void btnNext_Click(object sender, System.EventArgs e)
{
CurrentPage = (int)(ViewState["CurrentPage"]);
CurrentPage++;
string lastid = DataGrid1.Items[9].Cells[0].Text;
cmdNext.Parameters["@customerid"].Value = lastid;
FillGrid(cmdNext);
}
#region
Code généré par le Concepteur Web Form
override
protected
void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private
void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.cmdNext = new System.Data.SqlClient.SqlCommand();
this.cmdPrevious = new System.Data.SqlClient.SqlCommand();
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"monserveur\";packet size=4096;integrated security=SSPI;data s" +
"ource=\"monserveur\";persist security info=False;initial catalog=Northwind";
//
// cmdNext
//
this.cmdNext.CommandText = "SELECT TOP 10 CustomerID, CompanyName, City FROM Customers WHERE (CustomerID > @c" +
"ustomerid) ORDER BY CustomerID";
this.cmdNext.Connection = this.sqlConnection1;
this.cmdNext.Parameters.Add(new System.Data.SqlClient.SqlParameter("@customerid", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
//
// cmdPrevious
//
this.cmdPrevious.CommandText = "SELECT TOP 10 CustomerID, CompanyName, City FROM Customers WHERE (CustomerID >= @" +
"customerid) ORDER BY Custom";
this.cmdPrevious.Connection = this.sqlConnection1;
this.cmdPrevious.Parameters.Add(new System.Data.SqlClient.SqlParameter("@customerid", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
this.btnPrevious.Click += new System.EventHandler(this.btnPrevious_Click);
//
// sqlCommand1
//
this.sqlCommand1.CommandText = "SELECT COUNT(CustomerID) AS Expr1 FROM Customers";
this.sqlCommand1.Connection = this.sqlConnection1;
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private
void btnPrevious_Click(object sender, System.EventArgs e)
{
btnNext.Enabled = true;
CurrentPage = (int)(ViewState["CurrentPage"]);
CurrentPage--;
if (CurrentPage >= 0)
{
string firstid;
firstid = (string)(ViewState[CurrentPage.ToString()]);
cmdPrevious.Parameters["@customerid"].Value = firstid;
FillGrid(cmdPrevious);
}
}
}
}
et merci pour votre rèponse........