*****************************************************************************
ascx.cs文件代码
public class FriendUploadPic:UserControl

       mysuoyu.Fun Fun=new mysuoyu.Fun();
       mysuoyu.sqlconn conn=new mysuoyu.sqlconn();
       mysuoyu.LoginCk Ck=new mysuoyu.LoginCk();
       mysuoyu.CheckFriend CF=new mysuoyu.CheckFriend();
       protected Button UpLoadButton;
       protected Button DelPic;
       protected DataList MyList;
   protected Label lblCurrentPage;
   protected Label lblRecordCount;
   protected Label lblPageCount;
   protected Label lblPageSize;
   protected Label NoList;
   protected LinkButton lbtFirst;
   protected LinkButton lbtLast;          
   protected LinkButton lbtNext;
   protected LinkButton lbtPre;
   int pagesize=6;//设置每页记录数
       public string Rinfo,Error_Msg,Uname,BigName,SmallName,BigUrl,SmallUrl,PicContent,ImgWidth,ImgHeight,ImgSize,Oper;
       public int Par_Pro,Par_Pic,Fid,Uid,Grade;
       private string sql;
       private SqlCommand cmd;
       private SqlDataReader dr;
       private void Page_Load(Object sender, EventArgs e)
   {
           if (!Page.IsPostBack)
           {
               ListPhoto();
         }
   }
       public void ListPhoto()
   {
               ViewState["pageindex"]=1;
           myBind((int)ViewState["pageindex"]);
           cmdState((int)ViewState["pageindex"]);
           lblCurrentPage.Text=ViewState["pageindex"].ToString();
           lblPageCount.Text=PgCount().ToString();
           lblRecordCount.Text=RsCount().ToString();
           lblPageSize.Text=pagesize.ToString();
   }
       //计算记录数 
       public int RsCount() 
       {
              int intCount=0;
              conn.open();
          //判断有否图片存在
              sql="select count(Fpid) from User_FriendPhoto where Fp_Fid="+Fid;
              cmd=new SqlCommand(sql,conn.link); 
              dr=cmd.ExecuteReader();
              if  (dr.Read())
              {
                   intCount = Convert.ToInt32(dr[0].ToString());
              }
              if  (intCount==0)
              {
                   NoList.Text="<center>很抱歉,您现在还没有上传任何图片。</center>";
              }
              dr.Close();
              cmd.Dispose();
              conn.close();                                              
              return intCount;
       }
       public int PgCount()//计算页数
   {
        if  (RsCount()%pagesize==0)
           return RsCount()/pagesize;
        else
           return RsCount()/pagesize+1;
   }

解决方案 »

  1.   

    public void myBind(int PgNo)
           {
                  try
                  {
                       //读出图片记录
                      int rsBegin,rsEnd,n;
                 string[] rsPage=new string[7]; 
                 rsEnd=PgNo*pagesize-1;
                 rsBegin=(PgNo-1)*pagesize;
                 if(rsEnd>=RsCount())
               rsEnd=RsCount()-1;
                 SqlDataAdapter da;
                 sql="select * from User_FriendPhoto where Fp_Fid="+Fid;
                       conn.open();
                       da=new SqlDataAdapter(sql,conn.link);
                       DataSet ds = new DataSet();
                       da.Fill(ds,"User_FriendPhoto");
                       da.Dispose();
                       //生成临时表
                 ds.Tables.Add("page");
                 ds.Tables["page"].Columns.Add("Pic_ID");
                 ds.Tables["page"].Columns.Add("Pic_Content");
                 ds.Tables["page"].Columns.Add("Pic_FNameBig");
                 ds.Tables["page"].Columns.Add("Pic_FNameSmall");
                 ds.Tables["page"].Columns.Add("Pic_Width");
                 ds.Tables["page"].Columns.Add("Pic_Height");
                 ds.Tables["page"].Columns.Add("Pic_Lenght");
                 for(n=rsBegin;n<=rsEnd;n++)//填充临时表
                 {  
                      rsPage[0]=ds.Tables[0].Rows[n]["Fpid"].ToString();
                      //取指定数目的字符
                      string title=ds.Tables[0].Rows[n]["Fp_PicTitle"].ToString().Trim();
                      string content=title;
                      int len=title.Length;
                      if (len>8)
                      {
                                 title=title.Substring(0,8)+"...";
                      }
                              rsPage[1]=title;
                              string Path="User/"+Uname+"/Friend/";
                      rsPage[2]=ds.Tables[0].Rows[n]["Fp_BigName"].ToString().Trim();
                      string big=Path+rsPage[2];
                      rsPage[3]=ds.Tables[0].Rows[n]["Fp_SmallName"].ToString().Trim();
                      rsPage[3]=Path+rsPage[3];
                      //读取图片的像素及字节
                      string path = Server.MapPath(big); 
                      if  (File.Exists(path) == true)
                              {
                                   Bitmap img = new Bitmap(path);
                           rsPage[4]=img.Width.ToString();
                           rsPage[5]=img.Height.ToString();
                           img.Dispose();
                           FileInfo fi=new FileInfo(path);
                           double Size=((double)fi.Length)/1024;
                           string s=Convert.ToString(Size);
                           rsPage[6]=s.Substring(0,s.IndexOf(".")+3);
                              }
                              else
                              {
                                   rsPage[4]="0";
                           rsPage[5]="0";
                           rsPage[6]="0";
                              }
                      rsPage[3]="<a href='"+big+"' target='_blank'><img src='"+rsPage[3]+"' alt='"+content+"' border='0'></a>";
                      ds.Tables[1].Rows.Add(rsPage);
                   }                        
                         this.MyList.DataSource = ds.Tables["page"].DefaultView;
                         this.MyList.DataBind(); 
                   conn.close();
                   Par_Pro=2;
                  }
                  catch(System.Exception e1)
                  {
                         //系统错误处理
                         Par_Pro=1;
                         Rinfo=e1.Message;
                         Response.Write ("dd"+Rinfo);
                         Response.End();
                         Error_Msg=Fun.ErrorMsg("0");
                  }
           }
       public void cmdState(int curPage)
       {
                   if  (curPage==1)
                   {
                    lbtFirst.Enabled=false;
                    lbtPre.Enabled=false;
                   }
                   else
                   {
                    lbtFirst.Enabled=true;
                    lbtPre.Enabled=true;
                   }
                   if  (PgCount()>curPage)
                   {
                    lbtNext.Enabled=true;
                    lbtLast.Enabled=true;
                   }
                   else
                   {
                    lbtNext.Enabled=false;
                    lbtLast.Enabled=false;
                   }
       }
       public void Page_OnClick(Object sender,CommandEventArgs e) 
           { 
                           string arg = e.CommandName;
                           //判断cmd,以判定翻页方向 
                           switch(arg) 
                           { 
                             case "first": 
                             ViewState["pageindex"]=1; 
                             break;
                             case "Pre": 
                             ViewState["pageindex"]=(int)ViewState["pageindex"]-1; 
                             if ((int)ViewState["pageindex"]==0)
                             {
                                 ViewState["pageindex"]=1;
                             }
                             break; 
                             case "next": 
                             ViewState["pageindex"]=(int)ViewState["pageindex"]+1;
                             break;
                             case "last": 
                             ViewState["pageindex"]=PgCount();
                             break; 
                           }
                           myBind((int)ViewState["pageindex"]);
                     cmdState((int)ViewState["pageindex"]);
                     lblCurrentPage.Text=ViewState["pageindex"].ToString(); 
           }
           #region Web Form Designer generated code
       override protected void OnInit(EventArgs e)
       {
       //
       // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
       //
       
       InitializeComponent();
         base.OnInit(e);
       }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
       private void InitializeComponent()
       {    
       this.Load += new System.EventHandler(this.Page_Load);
       this.UpLoadButton.Click += new System.EventHandler(this.UpLoad);
       this.DelPic.Click += new System.EventHandler(this.del_selectid);
       }
       #endregion
      

  2.   

    已经解决了,那位来接分啊。原来是sql下一页的时候,没取到Fid值呵呵。。
      

  3.   

    原来用datagrid?好了?有现成分页!
      

  4.   

    呵呵,我用的是DataList,用习惯了好了,好了,结贴。。