当前位置: 代码迷 >> ASP.NET >> datalist显示信息的小有关问题.解决后立马结贴.帮帮忙.
  详细解决方案

datalist显示信息的小有关问题.解决后立马结贴.帮帮忙.

热度:4618   发布时间:2013-02-25 00:00:00.0
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 ProductionInfo : System.Web.UI.Page
{

  int CurrentPage;//当前页数
  int PageSize=4; //每页条数
  int PageCount=9; //总页数
  int RecordCount=9;//总条数
  SqlDataBase my_DataBase = new SqlDataBase();
  DataSet ds = new DataSet();
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!this.IsPostBack)
  {
  CurrentPage = 0;//当前页习惯设为0
  ViewState["PageIndex"] = 0;//页索引也设为0


  //计算总共有多少记录
  RecordCount = CalculateRecord();


  //计算总共有多少页
  if (RecordCount%PageSize == 0)
  {
  PageCount = RecordCount / PageSize;
  }
  else
  {
  PageCount = RecordCount / PageSize + 1;
  }

  this.TotalLbl.Text = PageCount.ToString();//显示总页数
  ViewState["PageCount"] = PageCount;//会话session 对整个 application 有效 ,而视图状态 viewstate相当于某个页面的 session

  this.DataListBind();//不可以放在初始化条件之前就绑定,那样的话,如果仅有一页的数据,“下一页”页仍然显示
  bind();
  }
   
  PageSize = 4;//每页9条记录
  }

  public string SubStr(string sString, int nLeng)
  {
  string sNewStr="";
  if (sString.Length <= nLeng)
  {
  return sString;
  }
  else
  {
  sNewStr= sString.Substring(0, nLeng);
  sNewStr = sNewStr + "......";
  }
  return sNewStr;
  }

  private void bind()//这个方法将数据库中产品内容读出来.显示在HyperLink上面.只显示100个字符..但是这样只能显示一条.因为我第页显示的是四条记录.我想这个显示的和datalist绑定的同步..
  {
  my_DataBase.SqlConnection_Open();
  SqlDataAdapter dar = new SqlDataAdapter("select a.fileContext,b.Production_Name,b.Production_id,b.type,b.Production_purpose from [File] as a,Production as b where b.Production_id=a.ID", my_DataBase.conn);
  dar.Fill(ds);
  HyperLink lb = (HyperLink)ProList.Items[0].FindControl("HyperLink2");

  string str = "";
  str = ds.Tables[0].Rows[0][4].ToString();
  lb.Text = str;
  lb.Text = SubStr(lb.Text, 100);
  my_DataBase.connection_close();

  }
  private int CalculateRecord()
  {
  try
  {
  int recordCount;
  my_DataBase.SqlConnection_Open();

  string sql = "select count(*) as count from Production";
  SqlCommand cmd = new SqlCommand(sql,my_DataBase.conn);
  SqlDataReader sdr = cmd.ExecuteReader();

  if (sdr.Read())
  {
  recordCount = Int32.Parse(sdr["count"].ToString());
  }


  else
  {
  recordCount = 0;
  }

  sdr.Close();
  my_DataBase.connection_close();
  相关解决方案