| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2520 人关注过本帖, 1 人收藏
标题:用按钮实现类似百度谷歌分页(交流)
只看楼主 加入收藏
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
结帖率:100%
收藏(1)
 问题点数:0 回复次数:19 
用按钮实现类似百度谷歌分页(交流)
用按钮实现类似百度谷歌分页

-----------------------------------源代码中的代码--------------------

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            HorizontalAlign="Center" Width="100%" EnableTheming="True">
        <PagerSettings FirstPageText="[首页]" LastPageText="[尾页]" NextPageText="[下一页]" PageButtonCount="5"
                PreviousPageText="[上一页]" />
        <FooterStyle VerticalAlign="Middle" />
        <Columns>
            <asp:BoundField HeaderText="会员昵称" DataField="UF_OWNERCOMM_USER" DataFormatString="{0:d}" />
            <asp:TemplateField HeaderText="头像">
                <ItemTemplate>
                    <img height="120" src="" width="120" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="楼号" DataField="UF_OWNERCOMM_FLORID" DataFormatString="{0:d}" />
            <asp:BoundField HeaderText="房间号" DataField="UF_OWNERCOMM_ROOMID" DataFormatString="{0:d}" />
            <asp:BoundField HeaderText="QQ号" DataField="UF_OWNERCOMM_QQ" DataFormatString="{0:d}" />
            <asp:BoundField HeaderText="MSN" DataField="UF_OWNERCOMM_MSN" DataFormatString="{0:d}" />
            <asp:BoundField HeaderText="电话" DataField="UF_OWNERCOMM_TEL" DataFormatString="{0:d}" />
        </Columns>
        <PagerTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server">[首页]</asp:LinkButton>
            <asp:LinkButton ID="LinkButton2" runat="server">[上一页]</asp:LinkButton>
            <asp:LinkButton ID="yi" runat="server">1</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="er" runat="server">2</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="san" runat="server">3</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="si" runat="server">4</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="wu" runat="server">5</asp:LinkButton>
            ……
            <asp:LinkButton ID="zong" runat="server">7</asp:LinkButton>
            <asp:LinkButton ID="LinkButton5" runat="server">>></asp:LinkButton>
            <asp:LinkButton ID="LinkButton3" runat="server">[下一页]</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="LinkButton4" runat="server">[尾页]</asp:LinkButton>
        </PagerTemplate>
        <PagerStyle HorizontalAlign="Right" VerticalAlign="Middle" Height="30px" />
        <HeaderStyle BackColor="White" />
    </asp:GridView>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            HorizontalAlign="Center" Width="100%" EnableTheming="True">
        <PagerSettings FirstPageText="[首页]" LastPageText="[尾页]" NextPageText="[下一页]" PageButtonCount="5"
                PreviousPageText="[上一页]" />
        <FooterStyle VerticalAlign="Middle" />
        <Columns>
            <asp:BoundField HeaderText="会员昵称" DataField="UF_OWNERCOMM_USER" DataFormatString="{0:d}" />
            <asp:TemplateField HeaderText="头像">
                <ItemTemplate>
                    <img height="120" src="" width="120" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="楼号" DataField="UF_OWNERCOMM_FLORID" DataFormatString="{0:d}" />
            <asp:BoundField HeaderText="房间号" DataField="UF_OWNERCOMM_ROOMID" DataFormatString="{0:d}" />
            <asp:BoundField HeaderText="QQ号" DataField="UF_OWNERCOMM_QQ" DataFormatString="{0:d}" />
            <asp:BoundField HeaderText="MSN" DataField="UF_OWNERCOMM_MSN" DataFormatString="{0:d}" />
            <asp:BoundField HeaderText="电话" DataField="UF_OWNERCOMM_TEL" DataFormatString="{0:d}" />
        </Columns>
        <PagerTemplate>
            <asp:LinkButton ID="shou" runat="server">[首页]</asp:LinkButton>
            <asp:LinkButton ID="shang" runat="server">[上一页]</asp:LinkButton>
            <asp:LinkButton ID="yi1" runat="server">1</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="er1" runat="server">2</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="san1" runat="server">3</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="si1" runat="server">4</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="wu1" runat="server">5</asp:LinkButton>
            ……
            <asp:LinkButton ID="zong1" runat="server">7</asp:LinkButton>
            <asp:LinkButton ID="zong" runat="server">>></asp:LinkButton>
            <asp:LinkButton ID="xia" runat="server">[下一页]</asp:LinkButton>&nbsp;
            <asp:LinkButton ID="wei" runat="server">[尾页]</asp:LinkButton>
        </PagerTemplate>
        <PagerStyle HorizontalAlign="Right" VerticalAlign="Middle" Height="30px" />
        <HeaderStyle BackColor="White" />
    </asp:GridView>

--------------------------------类里的代码----------------------------------------------

//分页绑定gridview
    public static DataSet binggv(string sqlcomm,string bm,GridView gv)
    {
        SqlConnection myconn = new SqlConnection (getconnstr());
        myconn.Open();
        SqlDataAdapter sda = new SqlDataAdapter(sqlcomm, myconn);
        DataSet ds = new DataSet();
        sda.Fill(ds,bm);
        gv.DataSource = ds;
        gv.DataBind();
        myconn.Close();
        return ds;
    }   

------------------------------.cs里的代码------------------------------------

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 index_txl : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindgv1();
            bindgv2();           
        }
    }
    protected void bindgv1()   //绑定gridview1
    {
        try
        {
            string sqlcomm = "select * from UF_OWNERCOMM where UF_OWNERCOMM_CHECK = 1";
            bindgridview(GridView1, sqlcomm, "zong", "yi", "er", "san", "si", "wu");
            Label1
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
    protected void bindgv2()    //绑定gridview2
    {
        try
        {
            string sqlcomm = "select * from UF_OWNERCOMM where UF_OWNERCOMM_CHECK = 0";
            bindgridview(GridView2, sqlcomm, "zong1", "yi1", "er1", "san1", "si1", "wu1");
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }   
    protected void bindgridview(GridView g,string s,string zong,string yi,string er,string san,string si,string wu)        
    {
        try
        {
            publicclass.binggv(s, "UF_OWNERCOMM", g);
            GridViewRow gvr = g.BottomPagerRow;
            ((LinkButton)gvr.Cells[0].FindControl(zong)).Text = Convert.ToString(g.PageCount);
            if (g.PageIndex <= 2)     //当点击的那个编码小于或等于2时 5个Button显示的内容
            {
                ((LinkButton)gvr.Cells[0].FindControl(yi)).Text = "1";
                ((LinkButton)gvr.Cells[0].FindControl(er)).Text = "2";
                ((LinkButton)gvr.Cells[0].FindControl(san)).Text = "3";
                ((LinkButton)gvr.Cells[0].FindControl(si)).Text = "4";
                ((LinkButton)gvr.Cells[0].FindControl(wu)).Text = "5";
            }
            else if ((g.PageIndex + 2) >= g.PageCount)      //当点击的那个编码大于或等于总页数时 5个Button显示的内容
            {
                ((LinkButton)gvr.Cells[0].FindControl(yi)).Text = Convert.ToString(g.PageCount - 4);
                ((LinkButton)gvr.Cells[0].FindControl(er)).Text = Convert.ToString(g.PageCount - 3);
                ((LinkButton)gvr.Cells[0].FindControl(san)).Text = Convert.ToString(g.PageCount - 2);
                ((LinkButton)gvr.Cells[0].FindControl(si)).Text = Convert.ToString(g.PageCount - 1);
                ((LinkButton)gvr.Cells[0].FindControl(wu)).Text = Convert.ToString(g.PageCount);
            }
            else
            {
                ((LinkButton)gvr.Cells[0].FindControl(yi)).Text = Convert.ToString(g.PageIndex - 2);
                ((LinkButton)gvr.Cells[0].FindControl(er)).Text = Convert.ToString(g.PageIndex - 1);
                ((LinkButton)gvr.Cells[0].FindControl(san)).Text = Convert.ToString(g.PageIndex);
                ((LinkButton)gvr.Cells[0].FindControl(si)).Text = Convert.ToString(g.PageIndex + 1);
                ((LinkButton)gvr.Cells[0].FindControl(wu)).Text = Convert.ToString(g.PageIndex + 2);
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
    //-------------1表示审核通过   0表示审核不通过
    //1下一页
    protected void LinkButton3_Click(object sender, EventArgs e)
    {   
        GridView1.PageIndex = GridView1.PageIndex + 1;
        bindgv1();
    }
    //1尾页
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        GridView1.PageIndex = GridView1.PageCount;
        bindgv1();
    }
    //1上一页
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        GridView1.PageIndex = GridView1.PageIndex - 1;
        bindgv1();
    }
    //1首页
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        GridView1.PageIndex = 0;
        bindgv1();
    }
    //1下一页 >>
    protected void LinkButton5_Click(object sender, EventArgs e)
    {
        GridView1.PageIndex = GridView1.PageIndex + 1;
        bindgv1();
    }
    //1尾页 Button
    protected void zong_Click(object sender, EventArgs e)
    {
        GridView1.PageIndex = GridView1.PageCount;
        bindgv1();
    }
    //1按钮1
    protected void yi_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView1.BottomPagerRow;
        GridView1.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("yi")).Text);
        bindgv1();
    }
    //1按钮2
    protected void er_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView1.BottomPagerRow;
        GridView1.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("er")).Text);
        bindgv1();
    }
    //1按钮3
    protected void san_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView1.BottomPagerRow;
        GridView1.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("san")).Text);
        bindgv1();
    }
    //1按钮4
    protected void si_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView1.BottomPagerRow;
        GridView1.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("si")).Text);
        bindgv1();
    }
    //1按钮5
    protected void wu_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView1.BottomPagerRow;
        GridView1.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("si")).Text);
        bindgv1();
    }
    //0尾页
    protected void wei_Click(object sender, EventArgs e)
    {
        GridView2.PageIndex = GridView2.PageCount;
        bindgv2();
    }
    //0下一页
    protected void xia_Click(object sender, EventArgs e)
    {
        GridView2.PageIndex = GridView2.PageIndex + 1;
        bindgv2();
    }
    //0总页 >>
    protected void zong_Click1(object sender, EventArgs e)
    {
        GridView2.PageIndex = GridView2.PageIndex + 1;
        bindgv2();
    }
    //0总页
    protected void zong1_Click(object sender, EventArgs e)
    {
        GridView2.PageIndex = GridView2.PageCount;
        bindgv2();
    }
    //0按钮5
    protected void wu1_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView2.BottomPagerRow;
        GridView2.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("wu1")).Text);
        bindgv2();
    }
    //0按钮4
    protected void si1_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView2.BottomPagerRow;
        GridView2.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("si1")).Text);
        bindgv2();
    }
    //0按钮3
    protected void san1_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView2.BottomPagerRow;
        GridView2.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("san1")).Text);
        bindgv2();
    }
    //0按钮2
    protected void er1_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView2.BottomPagerRow;
        GridView2.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("er1")).Text);
        bindgv2();
    }
    //0按钮1
    protected void yi1_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = GridView2.BottomPagerRow;
        GridView2.PageIndex = Convert.ToInt32(((LinkButton)gvr.Cells[0].FindControl("yi1")).Text);
        bindgv2();
    }
    //0上一页
    protected void shang_Click(object sender, EventArgs e)
    {
        GridView2.PageIndex = GridView2.PageIndex - 1;
        bindgv2();
    }
    //0首页
    protected void shou_Click(object sender, EventArgs e)
    {
        GridView2.PageIndex = 0;
        bindgv2();
    }
}
搜索更多相关主题的帖子: 谷歌 百度 源代码 按钮 True 
2008-06-28 09:35
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
谁有好点的方法  我想做的和百度的一样

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-28 14:07
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
顶一下

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-30 12:54
tomtory
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:705
专家分:0
注 册:2008-6-12
收藏
得分:0 
我记得gridview还是datalist自带了这种分页方式的嘛

如果非要自己做的话你这样写不适合  要用到太多的linkbutton了

建议在后台画控件
2008-07-01 15:14
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
果然有好方法
后台画控件   什么意思啊  

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-07-01 15:17
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
用代码动态输出控件吗?

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-07-01 15:17
tomtory
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:705
专家分:0
注 册:2008-6-12
收藏
得分:0 
对吗  可以这样理解  因为本来就是在后台生成的  哪么你可以直接在后台生成A标记就可以了
不用像现在这样放N个linkbutton了  这样写起太麻烦了!?
2008-07-01 15:21
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
好的我试一下

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-07-01 15:23
tomtory
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:705
专家分:0
注 册:2008-6-12
收藏
得分:0 
建议在前台放一个Literal控件

你可以看看  在运行好页面后查看源码  Literal控件解析出来后是没有HTML代码的
这样就不会影响你生成出来的代码放到页面上后的样式会不会改变
2008-07-01 15:24
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
多谢指点

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-07-01 15:24
快速回复:用按钮实现类似百度谷歌分页(交流)
数据加载中...
 
   



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

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