---@@@@@@@@@@@@@@@@@@@谁用过webdiyer的AspNetPage控件?高手请进,帮我看看
我的程序在没有查询时分页是正常的,但是在查询后,从第一页上看确实是查询的结果,但是在点下一页时显示的又是所有的纪录。郁闷阿
我的程序:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Not Page.IsPostBack) Then
cmd = New SqlCommand( "[dbo].[Page_RebResult] ", Conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add( "@pageindex ", 1)
cmd.Parameters.Add( "@pagesize ", 1)
cmd.Parameters.Add( "@docount ", True)
cmd.Parameters.Add( "@username ", User.Identity.Name)
conn.Open()
AspNetPager1.RecordCount = cmd.ExecuteScalar()
conn.Close()
BindData()
End If
'在此处放置初始化页的用户代码
End Sub
Sub AddCustomText()
aspnetpager1.CustomInfoText = "记录总数: <font color= 'blue '> <b> " + aspnetpager1.RecordCount.ToString() + " </b> </font> "
aspnetpager1.CustomInfoText += " 总页数: <font color= 'blue '> <b> " + aspnetpager1.PageCount.ToString() + " </b> </font> "
aspnetpager1.CustomInfoText += " 当前页: <font color= 'red '> <b> " + aspnetpager1.CurrentPageIndex.ToString() + " </b> </font> "
'Session( "page ") = aspnetpager1.CurrentPageIndex.ToString()
End Sub
Sub BindData()
cmd = New SqlCommand
cmd.Connection = Conn
cmd.CommandType = CommandType.StoredProcedure
If Not (ViewState( "doSearch ") Is Nothing) Then
cmd = New SqlCommand( "Result_Qery ", Conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add( "@salers ", salers.SelectedValue.Trim)
cmd.Parameters.Add( "@days ", days.SelectedValue.Trim)
cmd.Parameters.Add( "@month1 ", Month1.Text.Trim)
'cmd.Parameters.Add( "@username ", User.Identity.Name)
cmd.Parameters.Add( "@pageindex ", aspnetpager1.CurrentPageIndex)
cmd.Parameters.Add( "@pagesize ", aspnetpager1.PageSize)
cmd.Parameters.Add( "@docount ", False)
cmd.Parameters.Add( "@username ", User.Identity.Name)
Else
cmd.CommandText = "Page_RebResult "
cmd.Parameters.Add( "@pageindex ", aspnetpager1.CurrentPageIndex)
cmd.Parameters.Add( "@pagesize ", aspnetpager1.PageSize)
cmd.Parameters.Add( "@docount ", False)
cmd.Parameters.Add( "@username ", User.Identity.Name)
End If
Conn.Open()
DisResult.DataSource = cmd.ExecuteReader()
DisResult.DataBind()
Conn.Close()
Label3.Text = salers.SelectedValue
Label4.Text = days.SelectedValue
Label2.Text = aspnetpager1.RecordCount.ToString()
Label1.Text = aspnetpager1.PageCount.ToString()
Label5.Text = " "
'动态设置用户自定义文本内容
AddCustomText()
End Sub
Sub aspnetpager1_PageChanged(ByVal src As Object, ByVal e As Wuqi.Webdiyer.PageChangedEventArgs)
aspnetpager1.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
Sub SearchNews()
ViewState( "doSearch ") = "true "
Session( "Condition ") = 1
Dim srecords As Integer = 0
cmd = New SqlCommand( "Result_Qery ", Conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add( "@salers ", salers.SelectedValue.Trim)
cmd.Parameters.Add( "@days ", days.SelectedValue.Trim)
cmd.Parameters.Add( "@month1 ", Month1.Text.Trim)
cmd.Parameters.Add( "@pageindex ", aspnetpager1.CurrentPageIndex)
cmd.Parameters.Add( "@pagesize ", aspnetpager1.PageSize)
cmd.Parameters.Add( "@docount ", True)
cmd.Parameters.Add( "@username ", User.Identity.Name)
Conn.Open()
srecords = cmd.ExecuteScalar()
aspnetpager1.RecordCount = srecords
aspnetpager1.CurrentPageIndex = 1
Conn.Close()
BindData()
aspnetpager1.CustomInfoText = "记录总数: <font color= 'blue '> <b> " + aspnetpager1.RecordCount.ToString() + " </b> </font> "
aspnetpager1.CustomInfoText += " 总页数: <font color= 'blue '> <b> " + aspnetpager1.PageCount.ToString() + " </b> </font> "
aspnetpager1.CustomInfoText += " 当前页: <font color= 'red '> <b> " + aspnetpager1.CurrentPageIndex.ToString() + " </b> </font> "
Session( "page ") = aspnetpager1.CurrentPageIndex.ToString()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Month1.Text.Trim = " " Then
Page.RegisterStartupScript( "OK ", " <script lanuage= 'javascript '> alert( " "请填写你要查询的月份! " "); </script> ")
Else
SearchNews()
End If
End Sub
[解决办法]
肯定是你的查询条件没有传递过去
[解决办法]
你要保存查询条件
[解决办法]
从第一页上看确实是查询的结果,但是在点下一页时显示的又是所有的纪录
因为点下一页时,又执行了If (Not Page.IsPostBack) Then里的内容,又重新绑定了数据
在If (Not Page.IsPostBack)应该有参数去判断,是要绑定查询后结果,还是要绑定初始化的所有记录
[解决办法]
你是否 申明了下面的事件
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
BindData();
}
[解决办法]
aspnetpage,现在有6.0版本,用法和之前不同的
[解决办法]
你可以使用
string keyword = Request.QueryString[ "keyword "];
...
PagingInfo = " <a href= 'pager.aspx?keyword= " + keyword + "&page= " + xxPage + " '> " + xxPage + " </a> ";
的方式进行分页。keyword 就是每次要传递到关键字,xxPage 是页码。
[解决办法]
传递参数是能分页,但是我知道老兄,你以前写得程序又得重新改了
[解决办法]
顶ing
[解决办法]
UP起来!
[解决办法]
什么怎么办,上面不是有人回答了么?
[解决办法]
我倒是有一种解决方案,不过如果你和webdiyer给的示例中的代码完全一致的话,可能要改的地方也不少,我把我实现的意思和你说说,你看了之后再决定是否愿意这么做:
1、存储过程不能用原来的存储过程,而且一个页面读出数据用一个存储过程,这样便于搜索操作
下面有我提供的存储过程,网上很流行的一个实现分页的存储过程,当然你也可以自己写。
2、在实现搜索的方法中,把搜索条件存入ViewState中,在BindData()方法中判断其是否为空,如果不为空就加上条件,为空的话就不加此条件
示例:(C#写的,老兄对不住了)
/// <summary>
/// 绑定数据的方法,分页结合存储过程来实现,加入了根据搜索条件来进行绑定数据
/// </summary>
public void BindToGridView() {
SqlParameter[] sParams = new SqlParameter[6];
sParams[0] = new SqlParameter( "@tblName ", SqlDbType.VarChar, 255);
sParams[1] = new SqlParameter( "@fldName ", SqlDbType.VarChar, 255);
sParams[2] = new SqlParameter( "@PageSize ", SqlDbType.Int, 4);
sParams[3] = new SqlParameter( "@PageIndex ", SqlDbType.Int, 4);
sParams[4] = new SqlParameter( "@OrderType ", SqlDbType.Bit, 1);
sParams[5] = new SqlParameter( "@WhereStr ", SqlDbType.VarChar, 2000);
sParams[0].Value = "Product_Info ";
sParams[1].Value = "Product_ID ";
sParams[2].Value = Pager.PageSize;
sParams[3].Value = Pager.CurrentPageIndex;
sParams[4].Value = false;
string SearchStr = Convert.ToString(ViewState[ "Query "]);
if (SearchStr == null || SearchStr == " ") {
sParams[5].Value = InitialWhereStr;
}
else {
sParams[5].Value = "( " + InitialWhereStr + " and " + SearchStr + ") ";
}
//这里是微软提供的一个操作数据库的类,你可以不用管它
//知道是读出数据就行了
SqlDataReader sReader = SqlHelp.ExecuteReader(SqlHelp.YuanYeConnectionString, CommandType.StoredProcedure, "GetRecordSet ", sParams);
storage.DataSource = sReader;
storage.DataBind();
sReader.Close();
Pager.CustomInfoText = "记录总数: <font color=\ "blue\ "> <b> " + Pager.RecordCount.ToString() + " </b> </font> ";
Pager.CustomInfoText += " 总页数: <font color=\ "blue\ "> <b> " + Pager.PageCount.ToString() + " </b> </font> ";
Pager.CustomInfoText += " 当前页: <font color=\ "red\ "> <b> " + Pager.CurrentPageIndex.ToString() + " </b> </font> ";
}
存储过程:
Create PROCEDURE [dbo].[GetRecordSet](
@tblName varchar(255), -- 表名
@fldName varchar(255), -- 字段名,通过此字段排序和检索记录
@PageSize int=15, -- 页尺寸
@PageIndex int=1, -- 页码
@OrderType bit=0, -- 设置排序类型, 为0则升序,非 0 值则降序
@WhereStr varchar(2000)=null -- 查询条件 (注意: 不要加 where)
)
AS
declare @strSQL varchar(2000) -- 主语句
declare @strTmp varchar(100) -- 临时变量
declare @strOrder varchar(500) -- 排序类型
if @OrderType != 0 --降序
begin
set @strTmp = ' <(select min '
set @strOrder = ' order by [ ' + @fldName + '] desc '
end
else--升序
begin
set @strTmp = '> (select max '
set @strOrder = ' order by [ ' + @fldName + '] asc '
end
set @strSQL = 'select top ' + str(@PageSize) + ' * from [ '
+ @tblName + '] where [ ' + @fldName + '] ' + @strTmp + '([ '
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' [ '
+ @fldName + '] from [ ' + @tblName + '] ' + @strOrder + ') as tblTmp) '
+ @strOrder
if @WhereStr != ' '
set @strSQL = 'select top ' + str(@PageSize) + ' * from [ '
+ @tblName + '] where [ ' + @fldName + '] ' + @strTmp + '([ '
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' [ '
+ @fldName + '] from [ ' + @tblName + '] where ' + @WhereStr + ' '
+ @strOrder + ') as tblTmp) and ' + @WhereStr + ' ' + @strOrder
if @PageIndex = 1
begin
set @strTmp = ' '
if @WhereStr != ' '
set @strTmp = ' where ( ' + @WhereStr + ') '
set @strSQL = 'select top ' + str(@PageSize) + ' * from [ '
+ @tblName + '] ' + @strTmp + ' ' + @strOrder
end
Exec(@strSQL)
注意:这里的存储过程没有统计记录总数的功能,你可以自己改一下,也可以再写一个存储过程
还有什么问题你可以QQ联系我,我的QQ是13922607
[解决办法]
你的分页条件没有传过去