@@@@@@@ 页面没有查询时,分页是正常的,但是在查询后,再翻页出现问题,显示的是总的纪录不是查询的纪录。一直搞不定。
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
[解决办法]
看不到你分页的代码?注意分页用link的__DoPostBack方式来分,不要用链接.否则条件会丢失
[解决办法]
分页的时候确保 0 <= CurrentPageIndex <= 记录总数/PageSize
[解决办法]
绑定的时候要根据条件来判断,即是否是查询,给出相应的SQL就行了
[解决办法]
传递参数 有问题