Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Navigation
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.....................
 

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 3-Nov-12 7:07am
Edited 3-Nov-12 7:14am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
 
select top 1 * from tablename where idfield>5 order by idfield asc 

 
and if direction is move previous
 
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
  Permalink  
v2
Comments
Member 9472024 at 4-Nov-12 6:10am
   
any u give me any code project for ref i m not getting
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

this sp sample
 

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
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 293
1 Sergey Alexandrovich Kryukov 281
2 RyanDev 65
3 nv3 60
4 Mehdi Gholam 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 5 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100