| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 600 人关注过本帖
标题:分页问题
只看楼主 加入收藏
董晓云
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2010-4-5
结帖率:42.86%
收藏
已结贴  问题点数:5 回复次数:4 
分页问题
using System;
using System.Data;
using System.Data.SqlClient;
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;

namespace WebApplication6
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                DataGridDataBind();

            }
        }
        private void DataGridDataBind()
        {
            SqlConnection cn = new SqlConnection("server=127.0.0.1;uid=sa;pwd=1234;database=fen");
            cn.Open();
            string sql = "select * from wo";
            SqlDataAdapter dr = new SqlDataAdapter(sql, cn);
            DataSet ds = new DataSet();
            dr.Fill(ds);
            dg.DataSource = ds;
            dg.DataBind();
            cn.Close();

        }
        private void dg_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {
            //设置当前页的索引
            dg.CurrentPageIndex = e.NewPageIndex;
            DataGridDataBind();
        }
    }
}



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication6._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.

<html xmlns="http://www. >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
   
        <asp:DataGrid ID="dg" runat="server" Style="z-index: 100; left: 180px; position: absolute;
            top: 117px" AutoGenerateColumns="false" DataKeyField="id" AllowPaging="True" PageSize="5"
            PagerStyle-Mode="NumericPages" CellPadding="4" BackColor="White" BorderWidth="1px" Height="20px"
            BorderStyle="None" BorderColor="#3366CC">
            <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
                    <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
                    <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
                    <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
                    <Columns>
                       
                        <asp:BoundColumn DataField="y" HeaderText="标题"></asp:BoundColumn>
                        <asp:BoundColumn DataField="t" HeaderText="新闻内容"></asp:BoundColumn>
                        <asp:BoundColumn DataField="time" HeaderText="发布日期"></asp:BoundColumn>
                         <asp:HyperLinkColumn DataNavigateUrlField="id" DataNavigateUrlFormatString="detail.aspx?ID={0}" DataTextField="id"
                            HeaderText="编号"></asp:HyperLinkColumn>
                    </Columns>


        </asp:DataGrid>
        
   
   
    </form>
</body>
</html>
运行后点击第2页第3 页 表中内容不变,一直是第1页的内容,高手们帮忙看看哪不对?
搜索更多相关主题的帖子: class void public 
2010-04-15 15:16
saitor
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:5
帖 子:373
专家分:1520
注 册:2009-5-18
收藏
得分:3 
dg.CurrentPageIndex = e.NewPageIndex;
没用过分页控件,e.NewPageIndex;这个值一直是1吧,点了之后给它加1试试。或者你表里的内容就一页。
2010-04-15 20:39
董晓云
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2010-4-5
收藏
得分:0 
试了不行啊   我表里的内容有3页
2010-04-16 19:31
saitor
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:5
帖 子:373
专家分:1520
注 册:2009-5-18
收藏
得分:0 
dg.CurrentPageIndex =2;你写死看看是不是跳到第2页。这个我没用过。不行就自己写分页吧,又不难。
2010-04-16 22:16
董晓云
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2010-4-5
收藏
得分:0 
不行 自己分页  怎么分啊
2010-04-16 22:43
快速回复:分页问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017173 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved