惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
T
The Blog of Author Tim Ferriss
U
Unit 42
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
Vercel News
Vercel News
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
I
InfoQ
Y
Y Combinator Blog
F
Full Disclosure
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
S
SegmentFault 最新的问题
腾讯CDC
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Visual Studio Blog
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
T
Threatpost
GbyAI
GbyAI
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
L
LangChain Blog
T
Tenable Blog
C
Cisco Blogs
T
Threat Research - Cisco Blogs
Google Online Security Blog
Google Online Security Blog

博客园 - 江湖工夫

TextBox控件TextMode=Password时赋值 [转]随滚动条滚动的层(支持IE6,FF2) Iframe页面内容变更页面自动改变大小(非加载时自适应大小) 抓取网络文件的URL地址作附件发送 SQL注入的漏洞,过滤httprequest Visual SourceSafe应用守则[转] Microsoft SQL Server 分析服务 SQL中使用DISTINCT显示多个字段的方法(不使用DISTINCT了) Ajax的按钮事件效果 层的移动,使用了jquery asp.net(C#)处理数据一个通用类,包括存储过程,适用于初学者[转] IE和Firefox在JavaScript方面的兼容性(汇编) asp.net 对xml文件的读写,添加,修改,删除操作[转] 一些动画进度的图标链接 邹建的通用分页存储过程[转] 一个存储过程实现将Excel数据导入数据库 SQL SERVER事务处理[转] SQL与MDX语法的比较 一个存储过程
GridView分页后跳转其他页面进行添加,编辑,删除操作后,仍返回到当前页码[原]
江湖工夫 · 2008-02-21 · via 博客园 - 江湖工夫

1.App_CODE部分SqlHelper类添加一全局静态变量gdPageIndex.

    //记录GridView分页信息,全局静态变量
    public static string gdPageIndex = "0";

2.主页面CodeBehind代码,前台页面很简单,一个GridView控件而已,代码省略.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Main : System.Web.UI.Page
{
    
//数据添加,编辑,删除页面简称维护页.
    private string strSql = string.Empty;

    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            
this.bind(); //给GridView绑定数据.
        }

    }


    
protected void bind()
    
{
        strSql 
= "SELECT ID,MNTH,STAT,L12,RPT,DRILL FROM dbo.STATINFO ORDER BY MNTH DESC";
        DataSet ds 
= SqlHelper.GetDataSet(strSql);

        
this.grvMain.DataSource = ds;
        
this.grvMain.DataKeyNames = new string[] "ID" };
        
//Session["gvPageIndex"]的值在维护页设置.
        if (Session["gvPageIndex"== null)
        
{
            
//Session["gvPageIndex"]为null,即普通的第一次加载页面,不是从维护页返回的.
            if (!Page.IsPostBack)
             {
                  SqlHelper.gdPageIndex = "0";
                
this.grvMain.PageIndex = 0//普通加载,加载第一页数据.
             }
          }
        else if (Session["gvPageIndex"== "True")
        
{
            
//Session["gvPageIndex"]为True,即是从维护页返回的,True值在维护页设置.
            if (!Page.IsPostBack)
                
this.grvMain.PageIndex = Convert.ToInt32(SqlHelper.gdPageIndex); //调用保存在全局变量里的PageIndex值.
           
Session["gvPageIndex"] = null//此处Session值要清空,不然刷新页面就不会在第一页.
        }

        
this.grvMain.DataBind();
    }


    
protected void grvMain_PageIndexChanging(object sender, GridViewPageEventArgs e)
    
{
        
this.grvMain.PageIndex = e.NewPageIndex;
        SqlHelper.gdPageIndex 
= e.NewPageIndex.ToString(); //将当前PageIndex的值保存进全局变量gdPageIndex.
        this.bind();
    }

}

3.数据维护页面.前台代码省略,一数据更新按钮btnUpdate.下面是CodeBehind代码

    protected void btnUpdate_Click(object sender, EventArgs e)
    
{
        Session[
"gvPageIndex"= "True"//设置Session["gvPageIndex"]为True
        Response.Redirect("Main.aspx"); //转回主页面
    }

OK!