| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1962 人关注过本帖
标题:datalist实现类似百度分页(有点不明显的小毛病&&等待解决)
取消只看楼主 加入收藏
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
结帖率:100%
收藏
 问题点数:0 回复次数:5 
datalist实现类似百度分页(有点不明显的小毛病&&等待解决)
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;
using System.Data.SqlClient;
public partial class bbs_photo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {     
            publicclass.pageintex = 0;
            datelistbind();            
        }
    }
    protected void datelistbind()
    {
         
        string sqlcomm = "select * from UF_PICTURE";
        SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
        myconn.Open();
        SqlDataAdapter sdr = new SqlDataAdapter();
        DataSet ds = new DataSet();
        sdr.SelectCommand = new SqlCommand(sqlcomm, myconn);
        sdr.Fill(ds, "UF_PICTURE");
        PagedDataSource pds = new PagedDataSource();        //分页数据源
        pds.DataSource = ds.Tables["UF_PICTURE"].DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 4;
        pds.CurrentPageIndex = publicclass.pageintex;
        Response.Write(publicclass.pageintex);
        publicclass.count = pds.PageCount;
        DataList1.DataSource = pds;
        DataList1.DataBind();
        Response.Write(publicclass.count);
    }     
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Header)
        {
            Control objectcontorl5 = e.Item.FindControl("LinkButton5");
            Control objectcontorl6 = e.Item.FindControl("LinkButton6");
            Control objectcontorl9 = e.Item.FindControl("LinkButton9");
            Control objectcontorl10 = e.Item.FindControl("LinkButton10");
            Control objectcontorl11 = e.Item.FindControl("LinkButton11");
            Control objectcontorl7 = e.Item.FindControl("LinkButton7");
            Control objectcontorl8 = e.Item.FindControl("LinkButton8");      
            LinkButton bt5 = (LinkButton)objectcontorl5;
            LinkButton bt6 = (LinkButton)objectcontorl6;
            LinkButton bt9 = (LinkButton)objectcontorl9;
            LinkButton bt10 = (LinkButton)objectcontorl10;
            LinkButton bt11 = (LinkButton)objectcontorl11;
            LinkButton bt7 = (LinkButton)objectcontorl7;
            LinkButton bt8 = (LinkButton)objectcontorl8;         
            publicclass.yi1 = Convert.ToInt32(bt9.Text) -1;
            publicclass.er1 = Convert.ToInt32(bt10.Text) -1;
            publicclass.san1 = Convert.ToInt32(bt11.Text) -1;           
            if (publicclass.pageintex <= 1)
            {
                bt9.Text = "1";
                bt10.Text = "2";
                bt11.Text = "3";
            }
            else if (publicclass.pageintex >= publicclass.count - 2)
            {
                bt9.Text = Convert.ToString(publicclass.count - 2);
                bt10.Text = Convert.ToString(publicclass.count - 1);
                bt11.Text = Convert.ToString(publicclass.count);
            }
            else
            {
                bt9.Text = Convert.ToString(publicclass.pageintex - 1);
                bt10.Text = Convert.ToString(publicclass.pageintex);
                bt11.Text = Convert.ToString(publicclass.pageintex + 1);
            }
            if (publicclass.pageintex == 0)
            {
                bt5.Enabled = false;
                bt6.Enabled = false;               
            }           
            if (publicclass.pageintex == publicclass.count)
            {
                bt7.Enabled = false;
                bt8.Enabled = false;               
            }     
        }
        if (e.Item.ItemType == ListItemType.Footer)
        {         
            Control objectcontorl12 = e.Item.FindControl("LinkButton12");
            Control objectcontorl13 = e.Item.FindControl("LinkButton13");
            Control objectcontorl14 = e.Item.FindControl("LinkButton14");
            Control objectcontorl15 = e.Item.FindControl("LinkButton15");
            Control objectcontorl16 = e.Item.FindControl("LinkButton16");
            Control objectcontorl17 = e.Item.FindControl("LinkButton17");
            Control objectcontorl18 = e.Item.FindControl("LinkButton18");            
            LinkButton bt12 = (LinkButton)objectcontorl12;
            LinkButton bt13 = (LinkButton)objectcontorl13;
            LinkButton bt14 = (LinkButton)objectcontorl14;
            LinkButton bt15 = (LinkButton)objectcontorl15;
            LinkButton bt16 = (LinkButton)objectcontorl16;
            LinkButton bt17 = (LinkButton)objectcontorl17;
            LinkButton bt18 = (LinkButton)objectcontorl18;           
            publicclass.yi2 = Convert.ToInt32(bt14.Text) - 1;
            publicclass.er2 = Convert.ToInt32(bt15.Text) - 1;
            publicclass.san2 = Convert.ToInt32(bt16.Text) - 1;
            if (publicclass.pageintex <= 1)
            {
                bt14.Text = "1";
                bt15.Text = "2";
                bt16.Text = "3";
            }
            else if (publicclass.pageintex >= publicclass.count - 2)
            {
                bt14.Text = Convert.ToString(publicclass.count - 2);
                bt15.Text = Convert.ToString(publicclass.count - 1);
                bt16.Text = Convert.ToString(publicclass.count);
            }
            else
            {
                bt14.Text = Convert.ToString(publicclass.pageintex - 1);
                bt15.Text = Convert.ToString(publicclass.pageintex);
                bt16.Text = Convert.ToString(publicclass.pageintex + 1);
            }
            if (publicclass.pageintex == 0)
            {
                bt12.Enabled = false;
                bt13.Enabled = false;                 
            }
            if (publicclass.pageintex == publicclass.count)
            {
                bt17.Enabled = false;
                bt18.Enabled = false;                 
            }     
        }
    }
    protected void LinkButton5_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = 0;
        datelistbind();
    }
    protected void LinkButton6_Click(object sender, EventArgs e)
    {      
        publicclass.pageintex = 0;
        datelistbind();      
    }
    protected void LinkButton9_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = Convert.ToInt32(publicclass.yi1);
        datelistbind();
    }
    protected void LinkButton10_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = Convert.ToInt32(publicclass.er1);
        datelistbind();
    }
    protected void LinkButton11_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = Convert.ToInt32(publicclass.san1);         
        datelistbind();
    }
    protected void LinkButton7_Click(object sender, EventArgs e)
    {      
        publicclass.pageintex = publicclass.pageintex + 1;
        datelistbind();      
    }
    protected void LinkButton8_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = publicclass.count;
        datelistbind();
    }
    protected void LinkButton12_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = 0;
        datelistbind();
    }
    protected void LinkButton13_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = publicclass.pageintex - 1;
        datelistbind();
    }
    protected void LinkButton14_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = Convert.ToInt32(publicclass.yi2);
        datelistbind();
    }
    protected void LinkButton15_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = Convert.ToInt32(publicclass.er2);
        datelistbind();
    }
    protected void LinkButton16_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = Convert.ToInt32(publicclass.san2);
        datelistbind();
    }
    protected void LinkButton17_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = publicclass.pageintex + 1;
        datelistbind();
    }
    protected void LinkButton18_Click(object sender, EventArgs e)
    {
        publicclass.pageintex = publicclass.count;
        datelistbind();
    }
}
//前台代码
--------------------------------------------------------
<asp:DataList ID="DataList1" runat="server" HorizontalAlign="Center" RepeatColumns="2">
        <ItemTemplate>
<div class="right_tu_1 bor_r">
<h3>效果图12</h3>
<span> <asp:Image ID="Image1" runat="server" Height="160px" Width="258px" ImageUrl="~/"/><%# Eval("UF_PICTURE_ADDRESS")%><label>上 传 者:<asp:LinkButton ID="LinkButton2" runat="server"><%# Eval("UF_PICTURE_USER")%></asp:LinkButton>

    上传时间:<asp:LinkButton ID="LinkButton3" runat="server"><%# Eval("UF_PICTURE_TIME")%></asp:LinkButton>
     
所属分类:<asp:LinkButton ID="LinkButton4" runat="server"><%# Eval("UF_PICTURE_TYPE")%></asp:LinkButton><a href="#"></a>

<a href="#" class="sq">
    <asp:LinkButton ID="LinkButton1" runat="server">进入评论</asp:LinkButton></a>点击次数:<%# Eval("UF_PICTURE_VISITQUANTITY")%> 次</label>
</span>
</div>
        </ItemTemplate>
        <HeaderTemplate>
            <div class="fenye">
                <label>
                    <asp:LinkButton ID="LinkButton20" runat="server" BackColor="Transparent" BorderColor="Transparent"
                        BorderStyle="None">上传图片</asp:LinkButton><a href="#"></a></label>
                <span style="width: 429px">共有<strong>28</strong>张图片 共3页
                    <asp:LinkButton ID="LinkButton5" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">首页</asp:LinkButton><a href="#"></a>
                    <asp:LinkButton ID="LinkButton6" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">< 上一页</asp:LinkButton><a href="#"> </a>
                    <asp:LinkButton ID="LinkButton9" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">1</asp:LinkButton><a href="#"></a>
                    <asp:LinkButton ID="LinkButton10" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">2</asp:LinkButton><a href="#"></a>
                    <asp:LinkButton ID="LinkButton11" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">3</asp:LinkButton>
                    <asp:LinkButton ID="LinkButton7" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">下一页 > </asp:LinkButton>
                    <asp:LinkButton ID="LinkButton8" runat="server" Width="24px" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">尾页</asp:LinkButton><a href="#"></a></span></div>
        </HeaderTemplate>
        <FooterTemplate>
            <div class="fenye" id="fenye" style="width: 877px">
                <label>
                    <asp:LinkButton ID="LinkButton19" runat="server" BackColor="Transparent" BorderColor="Transparent"
                        BorderStyle="None">上传图片</asp:LinkButton><a href="#"></a></label>
                <span style="width: 416px">共有<strong>28</strong>张图片 共<strong>3</strong>页
                    <asp:LinkButton ID="LinkButton12" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">首页</asp:LinkButton><a href="#"></a>
                    <asp:LinkButton ID="LinkButton13" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">< 上一页</asp:LinkButton><a href="#">
                    </a>
                    <asp:LinkButton ID="LinkButton14" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">1</asp:LinkButton><a href="#"></a>
                    <asp:LinkButton ID="LinkButton15" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">2</asp:LinkButton>
                    <asp:LinkButton ID="LinkButton16" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">3</asp:LinkButton>
                    <asp:LinkButton ID="LinkButton17" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">上一页 > </asp:LinkButton>
                    <asp:LinkButton ID="LinkButton18" runat="server" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None">尾页</asp:LinkButton><a href="#"></a></span></div>
        </FooterTemplate>
    </asp:DataList>" border="0" />
搜索更多相关主题的帖子: 百度 datalist 毛病 
2008-07-01 15:22
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
效果如下
首页  上一页  1 2 3  下一页  尾页
这个代码有问题   但我找不到是那里的错误  点击2时还正常   点击3或1时没效果   希望看到的高人能给予指点

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-07-01 15:22
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
类里的代码
public static int  yi1, er1, san1,yi2, er2,san2,count,pageintex;

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-07-01 15:25
雪雨星风
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:58
雪雨星风
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 16:49
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
晕啊  你们的都有弊端   不自动编号你还要判断ID是否重复
绑定在控件上的ID并不代表就是显示的那个ID
把数据库中的ID绑定到控件上  然后在生成一个连续的ID用来显示不就完了
和在线考试的原理一样   考题都是随机抽的  但显示的全是连续的

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-07-01 18:03
快速回复:datalist实现类似百度分页(有点不明显的小毛病&&等待解决)
数据加载中...
 
   



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

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