Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I have create a page that can navigate next previous first and last
Its working If i directly click on button

But if i want on text change of any particular record data will fill as i written but if i want to next of that record or previous of that record its not working so please any one can tell me how can i go next or previous record of particular record after my text change event called.....................


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;

public partial class SuppliersMaster : System.Web.UI.Page
{
    DataSet ds;
    int i;
    string query;
    erp erp = new erp();  //consider i hv created all methods in this class
    protected void txtSuplId_TextChanged(object sender, EventArgs e)
    {
       
       
     
          
            SqlDataReader dr = erp.select1("selectsuppmstr", txtSuplId.Text.Trim());
            if (dr.HasRows)
            {
               
                while (dr.Read())
                {
                    txtSuplId.Text = txtSuplId.Text.ToUpper();
                    txtSuplName.Text = (string)dr["supl_name"].ToString();
                    txtAddress.Text = (string)dr["supl_address"].ToString();
                    txtSuplCity.Text = (string)dr["supl_city"].ToString();
                    txtPin.Text = (string)dr["supl_pin"].ToString();
                    txtSuplCountry.Text = (string)dr["supl_country"].ToString();
                    txtTel.Text = (string)dr["supl_telephone"].ToString();
                    txtFax.Text = (string)dr["supl_fax"].ToString();
                    
                   
                }
            }
           
       
        }

   
    public void data()
    {
        txtSuplId.Text = ds.Tables[0].Rows[i]["supl_id"].ToString();
        txtSuplName.Text = ds.Tables[0].Rows[i]["supl_name"].ToString();
        txtAddress.Text = ds.Tables[0].Rows[i]["supl_address"].ToString();
        txtSuplCity.Text = ds.Tables[0].Rows[i]["supl_city"].ToString();
        txtPin.Text = ds.Tables[0].Rows[i]["supl_pin"].ToString();
        txtSuplCountry.Text = ds.Tables[0].Rows[i]["supl_country"].ToString();
        txtTel.Text = ds.Tables[0].Rows[i]["supl_telephone"].ToString();
        txtFax.Text = ds.Tables[0].Rows[i]["supl_fax"].ToString();

      
     
    }
    protected void btnFirst_Click(object sender, EventArgs e)
    {
        ds = erp.fillds("navigationitemmstr"); //store procedure 
        if (ds.Tables[0].Rows.Count>0)
        {
            i = 0;
            data();
            btnFirst.Focus();
        }
         querystring["id"]=i;
    }
    protected void btnLast_Click(object sender, EventArgs e)
    {
        ds = erp.fillds("navigationitemmstr"); //store procrdure 
        if (ds.Tables[0].Rows.Count > 0)
        {
            i = ds.Tables[0].Rows.Count-1;
            data();
            btnLast.Focus();
        }
    }
    protected void btnPrev_Click(object sender, EventArgs e)
    {
        ds = erp.fillds("navigationitemmstr"); //store procedure 
        if(request.querystring["id"]!=null)
         { i=request.querystring["id"].toString(); }
        if (i==ds.Tables[0].Rows.Count-1||i!=0)
        {
            if (i!=0)
            {
                i--;
                data();
                btnPrev.Focus();
            }
              querystring["id"]=i;
          
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        if(request.querystring["id"]!=null)
         { i=request.querystring["id"].toString(); }
        ds = erp.fillds("navigationitemmstr"); //store procedure 
        if (i < ds.Tables[0].Rows.Count - 1 )
        {
            i++;
            data();
            btnNext.Focus();

        }
          querystring["id"]=i;
    }
}


I have used querystring if their is another method please tell me

[Edit]Code block language changed: from HTML to C#[/Edit]
Posted
Updated 3-Nov-12 7:14am
v3

select * from (select tablename.*,ROW_NUMBER() over(order by emp_id asc)as RowNum from tablename)x where emp_id=@id
from this
i get row number
and that row number i store in my static i
 
Share this answer
 
this sp sample


SQL
Create PROCEDURE [dbo].[Navigate_Professions]
    @ID int,
    -- MoveFirst 1
    -- Movelast 2
    -- MoveNext 3
    -- MovePrevious 4
    @Direction tinyint

    AS
BEGIN
    if(@Direction =1)
     select top 1 * from LPB_Profession order by Profession_ID asc
    if(@Direction =2)
     select top 1 * from LPB_Profession order by Profession_ID desc
    if(@Direction =3)
     select top 1 * from LPB_Profession WHERE Profession_ID > @ID order by Profession_ID asc
    if(@Direction =4)
     select top 1 * from LPB_Profession WHERE Profession_ID < @ID order by Profession_ID desc


END



and in every method just call the procedure

inside Movefirst call sp and pass @Id with null and @Direction with 1
inside Movelast call sp and pass @Id with null and @Direction with 2
inside Movenext call sp and pass @Id with CurrentID and @Direction with 3
inside MovePrivious call sp and pass @Id with CurrentID and @Direction with 4


then display retieved row on form
 
Share this answer
 
You have many faults in this model
- fist you use increment and decrement by 1 to get next and previous row and that is wrong bucause you may have id like for example ( 1,2,5,7,10)
-second you retrieve all records from table and put it in dataset you have to get only the record you want to disply for example you create sp with to two parameter first one is current id (int) and
second one is direction (tinyint)1 move first 2 move last 3 move next 4 moveprevious
and inside the sp get right record by current id for example
current id is 5 and direction move next
so your statmant will be

SQL
select top 1 * from tablename where idfield>5 order by idfield asc 


and if direction is move previous

SQL
select top 1 * from tablename where idfield<5 order by idfield desc



and so on

so you encapsulate all logic in the sp and retieve only one row and you dont have to use querystring you can you the value of current id from dispaly form id
 
Share this answer
 
v2
Comments
Member-515487 4-Nov-12 6:10am    
any u give me any code project for ref i m not getting

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