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

qustgg 2012-07-03 10:03:35
这是前台的部分代码:
<%@ 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();
}
}
}
}
...全文
108 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qustgg 2012-07-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
断点调试后再问问题
[/Quote]

点击“下一步”后没有执行button1_click事件,所以就空了。怎么改呢?
ycproc 2012-07-03
  • 打赏
  • 举报
回复


断点调试后再问问题
fox123871 2012-07-03
  • 打赏
  • 举报
回复
点击下一页你重新绑定数据源了吗?

62,067

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧