首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

像这样的分页控件在ASP.NET中怎么做呢

2012-04-24 
像这样的分页控件在ASP.NET中如何做呢?我用的是datalist做了个显示数据的模板,有点像百度搜索网页后那种想

像这样的分页控件在ASP.NET中如何做呢?

我用的是datalist做了个显示数据的模板,有点像百度搜索网页后那种
想问下像这样的分页控件如何做呢?
我只能实现点前一页和后一页
不能想这样是很多个按钮
能给代码我给200分,(我只有200分)

[解决办法]

C# code
 protected void Page_Load(object sender, EventArgs e)    {        if (!Page.IsPostBack)        {            BindData();        }    }    void BindData()    {        string BD_ID = "0";        if (Request.QueryString["Sort"] != null) sort = Request.QueryString["Sort"].ToString();        if (Request.QueryString["BrandID"] != null) BD_ID = Request.QueryString["BrandID"].ToString();        DataSet Ds = ProductProvider.Instance.GetViewMobileBySortExcuteProcdeure(sort,BD_ID);        PagedDataSource objPds = new PagedDataSource();        objPds.DataSource =Ds.Tables[0].DefaultView;        objPds.AllowPaging = true;        objPds.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["z_pagesize"]);        int CurPage;        if (Request.QueryString["Page"] != null)            CurPage = Convert.ToInt32(Request.QueryString["Page"]);        else            CurPage =0;        objPds.CurrentPageIndex = CurPage;        ddl_new_price1.DataSource = objPds;                ddl_new_price1.DataBind();        int PageCount = objPds.PageCount;        if (PageCount > 0)        {            WritePage(CurPage,PageCount);            li_PageCount.Text = " 第<b class='hong12'>" + (CurPage+1).ToString() + "</b> / <span class='hei12'>" + PageCount.ToString() + "</span>页 每页<b class='hei12'>" + objPds.PageSize.ToString() + "</b>款 共<b class='hei12'>" + Ds.Tables[0].Rows.Count.ToString() + "</b> 款";        }        else        {            lb_noFound.Text = "没有找到相关产品!";        }    }    void WritePage(int PageIndex, int PageCount)    {        StringBuilder str = new StringBuilder();        string url =  Request.RawUrl;        if (url.Length > 0)        {            if (url.IndexOf("_") != -1)            {                url = url.Substring(url.IndexOf("_")).Replace("#", "%23");            }        }        li_page.Text = string.Empty;        int cnt = 1;        if (PageCount > 0)        {            if (PageIndex != 0)            {                str.AppendLine("<a class='nor' href='0" + url + "'>首页</a>");            }            if (PageIndex < 5)            {                if (PageIndex > 0)                {                    str.AppendLine("<a class='nor' href='" + (PageIndex - 1) + url + "'>上一页</a>");                }                else                {                    str.AppendLine("<a class='nor' disabled>上一页</a>");                }                for (int i = 0; i < PageCount; i++)                {                    if (cnt == 6) break;                    if (i == PageIndex)                    {                        str.AppendLine("<a class='act'>" + (i + 1).ToString() + "</a>");                    }                    else                    {                        str.AppendLine("<a class='nor' href='" + i + url + "'>" + (i + 1) + "</a>");                    }                    cnt++;                }                if (PageCount - cnt > 0)                {                    str.AppendLine("<a class='point'>...</a>");                }                if (PageIndex < PageCount - 1)                {                    str.AppendLine("<a class='nor' href='" + (PageIndex + 1) + url + "'>下一页</a>");                }                else                {                    str.AppendLine("<a class='nor' disabled>下一页</a>");                }            }            else            {                str.AppendLine("<a class='nor' href='" + (PageIndex - 1) + url + "'>上一页</a>");                int startIndex = (int)(PageIndex / 5) * 5;                if (startIndex != 0)                {                    str.AppendLine("<a class='point'>...</a>");                }                for (int i = startIndex; i < PageCount; i++)                {                    if (cnt == 6) break;                    if (i == PageIndex)                    {                        str.AppendLine("<a class='act'>" + (i + 1).ToString() + "</a>");                    }                    else                    {                        str.AppendLine("<a class='nor' href='" + i + url + "'>" + (i + 1) + "</a>");                    }                    cnt++;                }                if (startIndex + 5 < PageCount)                {                    str.AppendLine("<a class='point'>...</a>");                }                if (PageIndex < PageCount - 1)                {                    str.AppendLine("<a class='nor' href='" + (PageIndex + 1) + url + "'>下一页</a>");                }                else                {                    str.AppendLine("<a class='nor' disabled>下一页</a>");                }            }        }        if (PageIndex != PageCount - 1)        {            str.AppendLine("<a class='nor' href='" + (PageCount - 1) + url + "'>末页</a>");        }        li_page.Text = str.ToString();    } 


[解决办法]
这个你可以采用输入出到界面的办法,在界面定义 一个div id=page,然后,在后台代码中,将这种分页的HTML代码输入到这个div里面
[解决办法]

看得图片吗?这种分页可以吗?
[解决办法]

再发一次,怎么看不到图片啊
[解决办法]

晕了,还看不到
[解决办法]

C# code
public DataTable BindNumericPageBarAndGetDataTable()         {             SqlConnection conn = null;             try             {                 try                 {                     conn = new SqlConnection(_ConnectionString);                     conn.Open();                 }                 catch (Exception ex)                 {                     string str=ex.ToString();                }                 SqlDataAdapter Da;                 DataSet ds;                DataSet dsCount = new DataSet();                         //**********************************************************************                 //** 分页基本参数                 //**********************************************************************                 int PageSize;                 if (_PageSize == 0)                {                     PageSize = 10;                 }                 else                 {                     PageSize = _PageSize;                 }                 /////////总记录数                 int TotalCount = 0;                 Da = new SqlDataAdapter(Sql, conn);                 Da.Fill(dsCount);                 TotalCount = dsCount.Tables[0].Rows.Count;                 dsCount.Clear();                 dsCount.Dispose();                         /////////总页数                 int TotalPage = Convert.ToInt32(TotalCount / PageSize + 1);                 /////////当前页                 int CurPage;                 if (Request.QueryString["Page"] == "")                {                     CurPage = 1;                 }                 else                 {                     CurPage = Convert.ToInt32(Request.QueryString["Page"]);                 }                 if (CurPage <= 0)                 {                     CurPage = 1;                 }                 if (CurPage > TotalPage)                 {                     CurPage = TotalPage;                 }                 GoPage.Text = CurPage.ToString();                 /////////开始ID号 da.Fill(ds, StartID, PageSize, "Life"),即从第几条开始填充数据                 int StartID;                 if (TotalCount > PageSize)                 {                     StartID = PageSize * (CurPage - 1);                 }                 else                 {                     StartID = 0;                 }                         //**********************************************************************                 //** 上一页 下一页 分页格式                 //**********************************************************************                 lblCurrentPage.Text = "第<font color=red>" + CurPage.ToString() + "</font>页";                 lblTotalPage.Text = "共<font color=red>" + Convert.ToString(TotalPage) + "</font>页";                 lblPageSize.Text = "<font color=red>" + PageSize.ToString() + "</font>条/页";                 lblTotalCount.Text = "共<font color=red>" + Convert.ToString(TotalCount) + "</font>条";                         if (CurPage > 1 & TotalPage > 1)                 {                     lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + URL;                     lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1" + URL;                 }                 if (CurPage < TotalPage & TotalPage > 1)                 {                     lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + URL;                     lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(TotalPage) + URL;                 }                         //**********************************************************************                 //** 数字分页格式                 //**********************************************************************                         ///////数字分页步长///////                 //********************************************原理示意图*******************************************************************                 //** CurPageBarLocation                 //**...|______↓____↓_____↓_______|_______________...........______|_32_________35___________39__|______.......                 //** |←------ PageBarStep -----→| ↑ ↑                 //** CurPageBarStart CurPageBarEnd                 //*************************************************************************************************************************                 //每个页码段的页码数                 if (TotalCount > PageSize)                 {                     int PageBarStep;                     if (_NumericPageBarStep == 0 )                     {                         PageBarStep = 5;                     }                     else                     {                         PageBarStep = _NumericPageBarStep;                     }                     //当前页所在的页码段,0开始,int()只取整数部分,不四舍五入                     int CurPageBarLocation = Convert.ToInt32(CurPage / PageBarStep);                     int CurPageBarStart;                     int CurPageBarEnd;                     if (CurPage == PageBarStep * CurPageBarLocation)                     {                         //当前页刚好可以整除PageBarStep,即刚好处在当前页码段的最后一页                         CurPageBarStart = (PageBarStep * (CurPageBarLocation - 1)) + 1;                         CurPageBarEnd = CurPage;                     }                     else                     {                         CurPageBarStart = PageBarStep * CurPageBarLocation + 1;                         //分页条开始页码数                         CurPageBarEnd = PageBarStep * (CurPageBarLocation + 1);                         //分页条结束页码数                     }                     if (CurPageBarEnd > TotalPage)                     {                         CurPageBarEnd = TotalPage;                     }                     while (CurPageBarStart <= CurPageBarEnd)                    {                         if (CurPageBarStart == CurPage)                         {                             lblNumberPage.Text += "&nbsp;<b><font color=red>" + CurPageBarStart.ToString() + "</font></b>";                         }                         else                        {                             lblNumberPage.Text += "&nbsp;<a href='" + Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPageBarStart) + _URL + "'>" + CurPageBarStart.ToString() + "</a>";                         }                         CurPageBarStart += 1;                     }                 }                         //**********************************************************************                 //** 绑定数据                 //**********************************************************************                 Da = new  SqlDataAdapter(Sql, conn);                 ds = new DataSet();                 if (TotalCount > PageSize)                 {                     Da.Fill(ds, StartID, PageSize, "MyDataSet");                 }                 else                 {                     Da.Fill(ds, "MyDataSet");                 }                 conn.Close();                conn.Dispose();                return ds.Tables[0];             }             finally             {                 if ((conn != null))                     ((IDisposable)conn).Dispose();             }         } 


[解决办法]
做个自定义控件也行
[解决办法]
上面的已经把代码给出来
最后你自己在页面设置哈对应CSS就能获得很好的效果
[解决办法]
先记下

热点排行