none
Repeater控件与AspNetpager怎么做的? RRS feed

  • 问题

  • 数据库为Data Source=(Local);Database=StudyDB;Uid=sa;Pwd=123,表TableBuy(UserID,Name,Goods)

    RepPage.aspx网页代码:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RepPage.aspx.cs" Inherits="RepPage" %>

    <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title>Repeater控件与AspNetPager</title>

    </head>

    <body>

        <form id="form1" runat="server">

        <h3>Repeater控件与AspNetPager</h3>

        <div>

            <asp:Repeater ID="Repeater1" runat="server">

            <ItemTemplate>

                <table>

                    <tr>

                        <td width=100px><a><%# DataBinder.Eval(Container.DataItem,"UserID") %></a></td>

                        <td width=200px><a><%# DataBinder.Eval(Container.DataItem,"Name") %></a></td>

                        <td width=200px><a><%# DataBinder.Eval(Container.DataItem,"Goods") %></a></td>

                    </tr>

                </table>

            </ItemTemplate>

            </asp:Repeater>

            <br /><br />

           <webdiyer:AspNetPager id="AspNetPager1"

           style="Z-INDEX: 102; LEFT: 256px; POSITION: absolute; TOP: 40px" 

           runat="server"

           Width="500px" 

           FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" 

           Height="40px" 

           ShowInputBox="Always" 

           TextAfterInputBox="页" 

           TextBeforeInputBox="跳转到第"

           AlwaysShow="True"

           PageSize="5"

           onpagechanged="AspNetPager1_PageChanged"

           >

        </webdiyer:AspNetPager> 

        </div>

        </form>

    </body>

    </html>

    RePage.aspx.cs代码:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Data;

    public partial class RepPage : System.Web.UI.Page
    {
        SqlConnection sqlcon;
        string strCon = "Data Source=(local);Database=StudyDB;Uid=sa;Pwd=123";
        protected void Page_Load(object sender, EventArgs e)
        {
            this.AspNetPager1.PageSize = 10;
            if (!IsPostBack)
            {
                dtList();
            }
        }
        public void dtBind()
        {
            sqlcon = new SqlConnection(strCon);
            sqlcon.Open();
            string sqlstr = "select * from TableBuy";
            SqlDataAdapter MyAdapter = new SqlDataAdapter(sqlstr, sqlcon);
            SqlCommand com = new SqlCommand(sqlstr, sqlcon);
            DataSet ds = new DataSet();
            MyAdapter.Fill(ds, "TableBuy");
            this.Repeater1.DataSource = ds;
            Repeater1.DataSourceID = "UserID";
            this.Repeater1.DataBind();
            sqlcon.Close();
        }
        protected void dtList()
        {
            sqlcon = new SqlConnection(strCon);
            sqlcon.Open();
            string sqlstr = "select * from TableBuy";
            SqlDataAdapter MyAdapter = new SqlDataAdapter(sqlstr, sqlcon);
            SqlCommand com = new SqlCommand(sqlstr, sqlcon);
            DataSet ds = new DataSet();
            MyAdapter.Fill(ds, "TableBuy");
            this.Repeater1.DataSource = ds;
            this.Repeater1.DataBind();
            AspNetPager1.RecordCount = Repeater1.DataSourceID.Count();
            sqlcon.Close();
        }
        protected  void AspNetPager1_PageChanged(object sender, System.EventArgs e) 
        {       //页索引改变方法 
            this.dtList(); 
        }
        
        
    }
    该怎么写这个AspNetpager呢?为什么这么写的对Repeater控件显示无效呢?

    2011年8月24日 5:16

答案