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

高分!自定义分页,点击“上一页”的时候无法显示数据,代码如上,请高手指导

2012-09-08 
高分求救!!!自定义分页,点击“下一页”的时候无法显示数据,代码如下,请高手指导。这是前台的部分代码:%@ Pag

高分求救!!!自定义分页,点击“下一页”的时候无法显示数据,代码如下,请高手指导。
这是前台的部分代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="EachCar.aspx.cs" Inherits="Report_EachCar" %>
<%@ MasterType TypeName="SiteMaster" %>
<%@ OutputCache Duration="60" VaryByParam="*" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
  <script language="javascript" type="text/javascript" src="../Scripts/My97DatePicker/WdatePicker.js"></script> 
   
  <p>
  <span class="style23">第</span><asp:Label ID="lblCurrent" runat="server" 
  CssClass="style23"></asp:Label>
  <span class="style23"><span>页 |每页</span><asp:Label ID="lblPageSize" 
  runat="server"></asp:Label>
  <span>条 |共有</span><asp:Label ID="lblPageTotal" runat="server"></asp:Label>
  <span>页 |共有</span></span><asp:Label ID="lblRowsTotal" runat="server" 
  CssClass="style23"></asp:Label>
  <span class="style23">条信息 |</span>
  <asp:HyperLink ID="hlFirst" runat="server" CssClass="style23">首页</asp:HyperLink>
  <span class="style23">| </span>
  <asp:HyperLink ID="hlPrev" runat="server" CssClass="style23">上一页</asp:HyperLink>
  <span class="style23">| </span>
  <asp:HyperLink ID="hlNext" runat="server" CssClass="style23">下一页</asp:HyperLink>
  <span class="style23">| </span>
  <asp:HyperLink ID="hlLast" runat="server" CssClass="style23">尾页</asp:HyperLink>
  </p>
   
</asp:Content>



这是后台的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using DBCONN;
using System.Configuration;

public partial class Report_EachCar : System.Web.UI.Page
{
  public static string BeginDate, EndDate, Team, Shift, Formula,StrCondition=" ";
  public static string RemoteConnStr = "";
   
  protected void Page_Load(object sender, EventArgs e)
  {
   
  }

  protected void Page_LoadComplete(Object sendr, EventArgs e)
  {
  DropDownList MachineID = (DropDownList)Master.FindControl("dropdownlist1");
  RemoteConnStr = MachineID.Text.Trim();

  if (!IsPostBack)
  {
  SqlConnection conn = new SqlConnection(RemoteConnStr);
  string strSQL = "select mater_name,mater_code from pmt_material order by mater_code";
  SqlCommand cmd = new SqlCommand(strSQL, conn);
  cmd.Connection.Open();
  SqlDataReader myReader = cmd.ExecuteReader();
  while (myReader.Read())
  {
  DropDownList4.Items.Add(new ListItem(myReader["mater_name"].ToString(), myReader["mater_code"].ToString()));


  }
  cmd.Connection.Close();

  }
  GridView1.DataBind();
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  //string BeginDate, EndDate, Team, Shift, Formula,StrCondition=" ";
  StrCondition = " ";
  int BeginDepartTure, EndDepartTure;
  BeginDate = TextBox1.Text;
  EndDate = TextBox2.Text;
  Team = DropDownList2.SelectedValue;
  Shift = DropDownList3.SelectedValue;
  Formula = DropDownList4.Text;
  BeginDepartTure = Int32.Parse(TextBox3.Text);
  EndDepartTure = Int32.Parse(TextBox4.Text);
  //保存页面的值
  //ViewState["enddate"] = TextBox2.Text;
  ViewState["begindate"] = TextBox1.Text;
   
  if (BeginDate != "") 
  {
  StrCondition = StrCondition+ "p1.Start_datetime > '" + BeginDate +"' and ";
  }
  if (EndDate != "")
  {
  StrCondition = StrCondition + "p1.Start_datetime < '" + EndDate + "' and ";
  }
  if (Formula != "0")
  {
  StrCondition = StrCondition + "p1.mater_code = '" + Formula.Trim() + "' and ";
  }
  if (BeginDepartTure.ToString() != "")
  {
  StrCondition = StrCondition + "p1.Serial_id > " + BeginDepartTure + " and ";
  }
  if (EndDepartTure.ToString() != "")
  {
  StrCondition = StrCondition + "p1.Serial_id < " + EndDepartTure + " and ";
  }
  if (Team != "0")
  {
  StrCondition = StrCondition + "p1.Oper = '" + Team + "' and ";
  }
  if (Shift != "0")
  {
  StrCondition = StrCondition + "p1.Shift_class = '" + Shift + "' ";
  }
  else if (Shift == "0")
  {
  StrCondition = StrCondition + "p1.Shift_class in ('1','2','3') ";
  }

  int CurrentPage, RowCount, PageCount;
  int PageSize = 20;
  if (Request["CurrentPage"] == null || Convert.ToInt32(Request["CurrentPage"]) < 1)
  {
  CurrentPage = 1;
  }
  else
  {
  CurrentPage = Convert.ToInt32(Request["CurrentPage"]);
  }

  //数据库操作
  DropDownList MachineID = (DropDownList)Master.FindControl("dropdownlist1");
  string RemoteConnStr = MachineID.Text.Trim();
  SqlConnection sqlconn = new SqlConnection(RemoteConnStr); //Second row
  //SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["ConnStr"].ToString());
  SqlCommand cmd = new SqlCommand("pagelist", sqlconn);
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Connection = sqlconn;
  SqlParameter[] prams ={
  new SqlParameter("@tablename",SqlDbType.VarChar,300),
  new SqlParameter("@fieldname",SqlDbType.VarChar,300),


  new SqlParameter("@condition",SqlDbType.VarChar,400),
  new SqlParameter("@pagesize",SqlDbType.Int),
  new SqlParameter("@currentpage",SqlDbType.Int),
  new SqlParameter("@orderid",SqlDbType.NVarChar,100),
  new SqlParameter("@sort",SqlDbType.Int),
  new SqlParameter("@rowcount",SqlDbType.Int),
  new SqlParameter("@pagecount",SqlDbType.Int)};
  prams[0].Value = " ppt_lot p1 left outer join pmt_material p2 on p1.Mater_code = p2.mater_code left outer join pmt_alarmcode p3 on p1.Barcode = p3.ac_detail ";//表名
  prams[1].Value = " p1.barcode,p1.Start_datetime,p2.mater_name,p1.Allche,p1.Serial_id,p1.Done_allrtime,p1.Done_rtime,p3.ac_bz1 ";//字段名
  prams[2].Value = StrCondition;
  prams[3].Value = PageSize;//每页显示条数
  prams[4].Value = CurrentPage;//当前页数
  prams[5].Value = " p1.barcode ";//主键
  prams[6].Value = 1;//排序方式,0表示降序,1表示升序
  prams[7].Direction = ParameterDirection.Output;//总记录数
  prams[8].Direction = ParameterDirection.Output;//总页数
  foreach (SqlParameter pram in prams)
  {
  cmd.Parameters.Add(pram);
  }
  try
  {
  if (sqlconn.State == ConnectionState.Closed)
  {
  sqlconn.Open();
  }
  SqlDataAdapter sda = new SqlDataAdapter();
  DataSet ds = new DataSet();
  sda.SelectCommand = cmd;
  sqlconn.Close();
  sda.Fill(ds);
  //数据库操作结束

  RowCount = (int)cmd.Parameters["@rowcount"].Value;
  PageCount = (int)cmd.Parameters["@pagecount"].Value;

  if (RowCount == 0)
  {
  Msg.Text = "没有对应的记录";
  Panel1.Visible = false;
  }

  if (CurrentPage > PageCount)
  {
  Response.Redirect("EachCar.aspx?CurrentPage=" + Convert.ToString(PageCount));
  Response.End();
  }
  if (RowCount != 0)
  {
  Panel1.Visible = true;
  this.lblCurrent.Text = Convert.ToString(CurrentPage);
  this.lblPageTotal.Text = Convert.ToString(PageCount);
  this.lblRowsTotal.Text = Convert.ToString(RowCount);
  this.lblPageSize.Text = Convert.ToString(PageSize);

  this.hlFirst.NavigateUrl = "EachCar.aspx?CurrentPage=1";
  this.hlPrev.NavigateUrl = "EachCar.aspx?CurrentPage=" + Convert.ToString(CurrentPage - 1);
  this.hlNext.NavigateUrl = "EachCar.aspx?CurrentPage=" + Convert.ToString(CurrentPage + 1);
  this.hlLast.NavigateUrl = "EachCar.aspx?CurrentPage=" + Convert.ToString(PageCount);
  }
  if (Convert.ToInt32(CurrentPage) == 1)
  {
  this.hlPrev.Enabled = false;
  this.hlFirst.Enabled = false;


  }
  if (Convert.ToInt32(CurrentPage) == PageCount)
  {
  this.hlNext.Enabled = false;
  this.hlLast.Enabled = false;
  }

  GridView1.DataSource = ds.Tables[0];
  GridView1.DataBind();
  }
  catch (SqlException ec)
  {
  Msg.Text = ec.Message.ToString();
  }
  finally
  {
  if (sqlconn.State == ConnectionState.Open)
  {
  sqlconn.Close();
  }
  }
  }
 }


[解决办法]
点击下一页你重新绑定数据源了吗?
[解决办法]


断点调试后再问问题

热点排行