Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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();
        }
    }
    }

In this next and previous statements only take first two rows of table. Please clear doubt in c#
Posted
Updated 18-May-12 2:35am
v4

C#
//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;;
 
Share this answer
 
Comments
JilRose 17-May-12 6:49am    
sorry! I can't understand.please explain it.
On a first look...

C#
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
}
 
Share this answer
 
Comments
JilRose 17-May-12 6:50am    
sir,i used this conditions. But i have the same problem in my page.
Then for previous your check should be if (inc > 0) isn't it? Also tell me how many rows you have what is the value of Maxrow?
 
Share this answer
 
Comments
JilRose 17-May-12 6:26am    
total rows r 5.

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