Asp.net导航按钮下一步以前的帮助 [英] Asp.net Navigation Buttons Next Previous Help

查看:97
本文介绍了Asp.net导航按钮下一步以前的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个页面,可以浏览下一个上一个第一个和最后一个
如果我直接单击按钮

但是,如果我想更改文本,则任何特定记录的数据都将按我的书面说明填入,但是如果我要转到该记录的下一个记录或该记录的前一个记录不起作用,那么任何人都可以告诉我如何去查找下一个或上一个记录我的文本更改事件后的特定记录称为............


 使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用使用System.Web.UI.WebControls;
使用使用System.Windows.Forms;
使用 System.Data.SqlClient;
使用 System.Data;

公共 部分  SuppliersMaster:System.Web .UI.页面
{
    数据集ds;
     int  i;
    字符串查询;
    erp erp =  erp(); // 考虑到我在此类中创建了所有方法
    受保护的 无效 txtSuplId_TextChanged(对象发​​件人,EventArgs e)
    {
       
       
     
          
            SqlDataReader dr = erp.select1(" ,txtSuplId.Text.Trim());
            如果(dr.HasRows)
            {
               
                 while (dr.Read())
                {
                    txtSuplId.Text = txtSuplId.Text.ToUpper();
                    txtSuplName.Text =(字符串)dr [" ].ToString();
                    txtAddress.Text =(字符串)dr [" ].ToString();
                    txtSuplCity.Text =(字符串)dr [" ].ToString();
                    txtPin.Text =(字符串)dr [" ].ToString();
                    txtSuplCountry.Text =(字符串)dr [" ].ToString();
                    txtTel.Text =(字符串)dr [" ].ToString();
                    txtFax.Text =(字符串)dr [" ].ToString();
                    
                   
                }
            }
           
       
        }

   
    公共 无效 data()
    {
        txtSuplId.Text = ds.Tables [ 0 ].rows [i] [" ].ToString();
        txtSuplName.Text = ds.Tables [ 0 ].rows [i] ["  0 ].Rows [i] [" ].ToString();
        txtSuplCity.Text = ds.Tables [ 0 ].Rows [i] [" ].ToString();
        txtPin.Text = ds.Tables [ 0 ].rows [i] [" ].ToString();
        txtSuplCountry.Text = ds.Tables [ 0 ].Rows [i] [" ].ToString();
        txtTel.Text = ds.Tables [ 0 ].rows [i] [" ].ToString();
        txtFax.Text = ds.Tables [ 0 ].rows [i] [" ].ToString();

      
     
    }
    受保护的 无效 btnFirst_Click(对象发​​件人,EventArgs e)
    {
        ds = erp.fillds(" ); // 存储过程
        如果(ds.Tables [ 0 ].Rows.Count> 0)
        {
            i =  0 ;
            数据();
            btnFirst.Focus();
        }
         querystring [" ] = i;
    }
    受保护的 无效 btnLast_Click(对象发​​件人,EventArgs e)
    {
        ds = erp.fillds(" ); // 存储过程
        如果(ds.Tables [ 0 ].Rows.Count  >   0 )
        {
            i = ds.Tables [ 0 ].Rows.Count-1;
            数据();
            btnLast.Focus();
        }
    }
    受保护的 无效 btnPrev_Click(对象发​​件人,EventArgs e)
    {
        ds = erp.fillds(" ); // 存储过程
        如果(request.querystring [" ]!== 为空)
         {i = request.querystring [" ].toString(); }
        如果(i == ds.Tables [ 0 ].Rows.Count-1 || i!=  0 )
        {
            如果(i!=  0 )
            {
                一世 - ;
                数据();
                btnPrev.Focus();
            }
              querystring [" ] = i;
          
        }
    }
    受保护的 无效 btnNext_Click(对象发​​件人,EventArgs e)
    {
        如果(request.querystring [" ]!== 为空)
         {i = request.querystring [" ].toString(); }
        ds = erp.fillds(" ); // 存储过程
        如果(i <  ds.Tables [ 0 ].Rows.Count- 1 )
        {
            i ++;
            数据();
            btnNext.Focus();

        }
          querystring [" ] = i;
    }
} 



我用过querystring如果它们是另一种方法,请告诉我

代码块语言已更改:从HTML到C#[/编辑]

解决方案

此模型存在很多错误
-首先使用递增和递减1来获取下一行和上一行,这是错误的bucause,例如,您可能具有id(1,2,5,7,10)
-秒,您从表中检索所有记录并将其放入数据集中,您只需要获取要显示的记录即可,例如,使用两个参数创建sp时,第一个是当前id(int)和
第二个是方向(tinyint)1前移2前移3后移4下移上一个
并在sp中通过当前ID获得正确的记录,例如
当前ID为5,方向下一步移动
所以你的状态会是

 选择 顶部  1  * 来自表名其中 idfield> 5  order  作者 idfield  asc  



如果方向是向前移动

 选择 顶部  1  * 来自表名其中 idfield< 5  order  作者 idfield  desc  




等等

因此,您可以将所有逻辑封装在sp中,而仅保留一行,而不必使用querystring,则可以从显示表单id中获取当前id的值

此sp示例


 创建 过程 [dbo].[Navigate_Professions]
     @ ID   int -  MoveFirst 1 
    -  Movelast 2 
    -  MoveNext 3 
    -  MovePrevious 4 
     @方向  tinyint 

     AS 
开始
    如果( @ Direction  = 1)
     选择 顶部  1  *  LPB_Profession 订单  Profession_ID 如果( @ Direction  = 2)
     选择 顶部  1  *  LPB_Profession 订单  Profession_ID 如果( @ Direction  = 3)
     选择 顶部  1  *  LPB_Profession  WHERE  Profession_ID>  @ ID  订单  by  Profession_ID  asc 
    如果( @ Direction  = 4)
     选择 顶部  1  *  LPB_Profession 位置 Profession_ID<  @ ID  订单  by  Profession_ID 描述


 END  




并在每个方法中只需调用过程

在Movefirst调用sp中并通过@Id传递null和@Direction传递1
在Movelast调用sp中,并传递带有空值的@Id和带有2
的@Direction 在Movenext调用sp中,并通过@ID和CurrentID传递@Direction和3
在MovePrivious调用sp中,并通过@ID和CurrentID传递和@Direction和4


然后在表格上显示重新绑定的行


从*选择(选择表名.*,ROW_NUMBER()超过(按emp_id asc排序)为从表名开始的RowNum)x其中emp_id = @ id
从这个
我得到行号
并将该行号存储在我的静态i


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]

解决方案

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


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


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


这篇关于Asp.net导航按钮下一步以前的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆