• 主页
  • ASP
  • .NET Framework
  • Web Services
  • VB
  • VC
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • LINQ

90分求这段代码的正确分页,现在还有点BUG,如何改,请详细一点

subitt 2004-12-26 01:51:38
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not Me.IsPostBack Then
orderbind()
End If
End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
orderbind()
End Sub
Sub orderbind()
Me.Label3.Text = Me.DropDownList1.SelectedItem.Text

Dim conn As New OleDbConnection("Data Source=""" & Me.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings("database")) & """;Provider=""Microsoft.Jet.OLEDB.4.0"";User ID=Admin")
Dim i As Integer = CInt(Me.DropDownList1.SelectedValue)
Dim mycom As String
If Me.DropDownList1.SelectedValue = 0 Or Me.DropDownList1.SelectedValue = 1 Then
'i = 3
mycom = "SELECT DISTINCT T_BookOrder.OrderID, T_BookOrder.Zonger, T_PaymentWay.PaymentWay, T_DeliveryWay.Way, T_BookOrder.OrderState, T_BookOrder.OrderTime, T_BookOrder.UserName FROM ((T_BookOrder INNER JOIN T_PaymentWay ON T_BookOrder.PaymentWayID = T_PaymentWay.PaymentWayID) INNER JOIN T_DeliveryWay ON T_BookOrder.WayID = T_DeliveryWay.WayID) WHERE (T_BookOrder.UserName = '16120300') ORDER BY T_BookOrder.OrderTime DESC"
Else
mycom = "SELECT DISTINCT T_BookOrder.OrderID, T_BookOrder.Zonger, T_PaymentWay.PaymentWay, T_DeliveryWay.Way, T_BookOrder.OrderState, T_BookOrder.OrderTime, T_BookOrder.UserName FROM ((T_BookOrder INNER JOIN T_PaymentWay ON T_BookOrder.PaymentWayID = T_PaymentWay.PaymentWayID) INNER JOIN T_DeliveryWay ON T_BookOrder.WayID = T_DeliveryWay.WayID) WHERE (T_BookOrder.UserName = '16120300') And (T_BookOrder.OrderState = '" & i & "') ORDER BY T_BookOrder.OrderTime DESC"
End If

Dim orderinfo As New OleDbDataAdapter(mycom, conn)

Dim ds As New DataSet
orderinfo.Fill(ds, "T_BookOrder")

Dim objPds As PagedDataSource = New PagedDataSource
objPds.DataSource = ds.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 10
Dim CurPage As Integer
If Not Request.QueryString("Page") Is Nothing Then
CurPage = Convert.ToInt32(Request.QueryString("Page"))
Else
CurPage = 1
End If
Dim zcount As Integer = Math.Ceiling(ds.Tables(0).Rows.Count / objPds.PageSize)

Me.Label2.Text = zcount
objPds.CurrentPageIndex = CurPage - 1
Me.Label1.Text = ds.Tables(0).Rows.Count
lblCurrentPage.Text = CurPage.ToString()
If (Not objPds.IsFirstPage) Then
Me.HyperLink2.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1)
End If
If (Not objPds.IsFirstPage) Then
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1)
End If
If (Not objPds.IsLastPage) Then
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1)
End If
If (Not objPds.IsLastPage) Then
Me.HyperLink5.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(zcount)
End If


Me.DataGrid1.DataSource = objPds
Me.DataGrid1.DataBind()
End Sub



我用一个dropdownlist来改变datagrid订单状态(i的值),如果每次只改变dropdownlist,就不会发生错误。但是如果你点了下一页,然后再去改变订单状态,如果i的值不够分2页,就会发生错误。我想问一下怎么解决呢?
...全文
50 点赞 收藏 3
写回复
3 条回复
subitt 2004年12月26日
If Not ds.Tables(0).Rows.Count > 10 Then
Me.HyperLink2.Enabled = False
Me.HyperLink5.Enabled = False
Me.lnkNext.Enabled = False
Me.lnkPrev.Enabled = False
Else
Me.HyperLink2.Enabled = True
Me.HyperLink5.Enabled = True
Me.lnkNext.Enabled = True
Me.lnkPrev.Enabled = True
Me.Label2.Text = zcount
objPds.CurrentPageIndex = CurPage - 1


我用过这个方法,感觉还是不行,比如i是1,翻到第3页之后,再改变i的值,然后CurrentPageIndex就停在第3页,不会在第1页了,所以我就不想用这个方法了,有好的吗,请详细一点。解决就结帖哈
回复 点赞
tengjian1981 2004年12月26日
up
回复 点赞
leihome 2004年12月26日
的值不够分2页则赋一个可以不出错的值
回复 点赞
发动态
发帖子
.NET技术社区
创建于2007-09-28

4.9w+

社区成员

66.8w+

社区内容

.NET技术交流专区
社区公告
暂无公告