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

一段代码,关于手写分页程序的,请看看哪里有有关问题~20分表心意

2012-02-14 
一段代码,关于手写分页程序的,请看看哪里有问题~20分表心意前台:formrunat server 共有 asp:Labelid

一段代码,关于手写分页程序的,请看看哪里有问题~20分表心意
前台:

<form   runat= "server ">
共有 <asp:Label   id= "lblRecordCount "   ForeColor= "red "   runat= "server "   /> 条记录          
当前为 <asp:Label   id= "lblCurrentPage "   ForeColor= "red "   runat= "server "   /> / <asp:Label   id= "lblPageCount "   ForeColor= "red "   runat= "server "   /> 页  

<asp:LinkButton   id= "lbnPrevPage "   Text= "上一页 "   CommandName= "prev "   OnCommand= "Page_OnClick "   runat= "server "   />
<asp:LinkButton   id= "lbnNextPage "   Text= "下一页 "   CommandName= "next "   OnCommand= "Page_OnClick "   runat= "server "   />

</form>


后台:

private   void   Page_Load(Object   sender,   EventArgs   e)
{
PageSize   =   10;
if(!IsPostBack)
{
CreateLabel(CreateTable());
        CurrentPage   =   0;
        ViewState[ "PageIndex "]   =   0;
        RecordCount   =   sum();
lblRecordCount.Text   =   RecordCount.ToString();
      PageCount   =   RecordCount   /   PageSize   +   1;
lblPageCount.Text   =   PageCount.ToString();
        ViewState[ "PageCount "]   =   PageCount;
}
}
}

        public   int   sum()
        {
OleDbConnection   conn=new   OleDbConnection(ConfigurationSettings.AppSettings[ "data "]+Server.MapPath(ConfigurationSettings.AppSettings[ "path "]));  
conn.Open();
                int   intCount;
                string   strCount   =   "select   count(*)   from   aa ";
                OleDbCommand   comm   =   new   OleDbCommand(strCount,   conn);
                intCount   =   Convert.ToInt32(comm.ExecuteScalar());
                return   intCount;
        }

        ICollection   CreateSource()
        {
                int   StartIndex;
                StartIndex   =   CurrentPage   *   PageSize;
                CreateLabel(CreateTable());  
        }

        public   void   Page_onClick(Object   sender,   CommandEventArgs   e)
        {
                CurrentPage   =   (int)ViewState[ "PageIndex "];
                PageCount   =   (int)ViewState[ "PageCount "];
                string   cmd   =   e.CommandName;
                switch   (cmd)


                {
                        case   "next ":
                                if   (CurrentPage   <   (PageCount   -   1))   CurrentPage++;
                                break;
                        case   "prev ":
                                if   (CurrentPage   >   0)   CurrentPage--;
                                break;
                }
                ViewState[ "PageIndex "]   =   CurrentPage;
                CreateLabel(CreateTable());  
        }

public   DataTable   CreateTable()
        {
OleDbConnection   conn=new   OleDbConnection(ConfigurationSettings.AppSettings[ "data "]+Server.MapPath(ConfigurationSettings.AppSettings[ "path "]));  
conn.Open();
string   sql= "select   *   FROM   aa ";
OleDbDataAdapter   da=new   OleDbDataAdapter(sql,conn);
DataTable   dt=new   DataTable();
da.Fill(dt,   StartIndex,   PageSize,   "aa ");
lbnNextPage.Enabled   =   true;
        lbnPrevPage.Enabled   =   true;
        if(CurrentPage==(PageCount-1))   lbnNextPage.Enabled   =   false;
        if(CurrentPage==0)   lbnPrevPage.Enabled   =   false;
        lblCurrentPage.Text   =   (CurrentPage+1).ToString();
return   dt;
        }

public   void   CreateLabel(DataTable   dt)
{
StringBuilder   sb   =   new   StringBuilder();
sb.Append( " <TABLE   id= 'Table1 '   style= 'Z-INDEX:   102;   LEFT:   8px;   POSITION:   absolute;   TOP:   8px '   cellSpacing= '1 '   cellPadding= '1 '   width= '300 '   border= '1 '> ");
for(int   i   =   0;i   <   dt.Rows.Count   ;   i++)
{
sb.Append( " <tr> ");
for(int   j   =   0   ;j   <   dt.Columns.Count;   j   ++)
{
sb.Append( " <td> ");
sb.Append(dt.Rows[i][j].ToString());
sb.Append( " </td> ");
}
sb.Append( " </tr> ");
}
sb.Append( " </table> ");
this.Response.Write(sb);
}

[解决办法]
private void Page_Load(Object sender, EventArgs e)
{
PageSize = 10;
if(!IsPostBack)
{
CreateLabel(CreateTable());
CurrentPage = 0;
ViewState[ "PageIndex "] = 0;
RecordCount = sum();
lblRecordCount.Text = RecordCount.ToString();


PageCount = RecordCount / PageSize + 1;
lblPageCount.Text = PageCount.ToString();
ViewState[ "PageCount "] = PageCount;
}
}
}
去掉最后一个}
[解决办法]
代码太多,我懒的看,哈哈,不过要帮LZ顶一下的,顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶

热点排行