public partial class Default2 : System.Web.UI.Page { #region SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["ad"].ConnectionString); DataSet ds; int Maxrow=0; int inc =0; #endregion protected void Page_Load(object sender, EventArgs e) { sc.Open(); ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter("select * from Customer", sc); da.Fill(ds, "ad"); Navigate(); Maxrow = ds.Tables["ad"].Rows.Count; } private void Navigate() { DataRow drow = ds.Tables["ad"].Rows[inc]; TextBox1.Text = drow.ItemArray.GetValue(1).ToString(); TextBox2.Text = drow.ItemArray.GetValue(2).ToString(); } protected void Next_Click(object sender, EventArgs e) { if (inc != Maxrow-1) { inc++; Navigate(); } else { MessageBox.Show("NoMore"); } } protected void Pre_click(object sender, EventArgs e) { if (inc > 0) { inc--; Navigate(); } //else //{ // MessageBox.Show("first "); //} } protected void Last_click(object sender, EventArgs e) { if (inc != Maxrow - 1) { inc = Maxrow - 1; Navigate(); } } protected void Button5_Click(object sender, EventArgs e) { if (inc != 0) { inc = 0; Navigate(); } } }
//Next - this.BindingContext[dt].Position += 1; //Previous this.BindingContext[dt].Position -= 1; //First this.BindingContext[dt].Position = 0; //last this.BindingContext[dt].Count = this.BindingContext[].Position -1;;
protected void Next_Click(object sender, EventArgs e) { if (inc < Maxrow-1) //(inc != Maxrow-1) <-- your condition { //you can move to the next record until current record isn't last } protected void Pre_click(object sender, EventArgs e) { if (inc >0) //(inc <0) <-- your condition { //you can move to the previous record until current record isn't first }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)