我已经更改了我的代码。我添加了updatepanel和链接按钮
标记
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:LinkButton ID="btnPrev" runat="server" OnClick="btnPrev_Click">PrevButton</asp:LinkButton>
<asp:TextBox id="txtHidden" style="width: 28px" value="1" runat="server" />
<asp:LinkButton ID="btnNext" runat="server" OnClick="btnNext_Click">NextButton</asp:LinkButton>
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<div class="latnewstitle">
Date:</div>
<%#DataBinder.Eval(Container.DataItem, "date")%><br />
<div class="latnewstitle">
title:</div>
<div class="latnewscontent">
<%#DataBinder.Eval(Container.DataItem, "title")%></div>
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl='<%# Eval("item_ID", "~/Details.aspx?ID={0}") %>'>See Details</asp:HyperLink>
<br />
<br />
<hr width="100px" />
<br />
</ItemTemplate>
</asp:Repeater>
</div>
</ContentTemplate>
</asp:UpdatePanel>
我的代码
Public Property PgNum() As Integer
Get
If ViewState("PgNum") IsNot Nothing Then
Return Convert.ToInt32(ViewState("PgNum"))
Else
Return 0
End If
End Get
Set(value As Integer)
ViewState("PgNum") = value
End Set
End Property
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
bindrepeater()
End If
End Sub
我添加了bindrepeater sub,因此将datato绑定到转发器
Protected Sub bindrepeater()
Dim strsql As String = "SELECT * FROM news ORDER BY news.item_ID DESC"
Dim sqlconn As New SqlConnection
sqlconn.ConnectionString = ConfigurationManager.ConnectionStrings("mycon").ToString
sqlconn.Open()
Dim cmd As New SqlCommand(strsql, sqlconn)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
cnt = ds.Tables(0).Rows.Count
'Dim table As New DataTable()
'da.Fill(table)
Dim pds As New PagedDataSource()
pds.DataSource = ds.Tables(0).DefaultView
pds.AllowPaging = True
pds.PageSize = 5
pds.CurrentPageIndex = PgNum
txtHidden.Text = PgNum
Dim vcnt As Integer = cnt / pds.PageSize
If PgNum < 1 Then
btnPrev.Visible = False
ElseIf PgNum > 0 Then
btnPrev.Visible = True
End If
If PgNum = vcnt Then
btnNext.Visible = False
ElseIf PgNum < vcnt Then
btnNext.Visible = True
End If
Repeater1.DataSource = pds
Repeater1.DataBind()
sqlconn.Close()
End Sub
'我的分页按钮
Protected Sub btnNext_Click(sender As Object, e As System.EventArgs) Handles btnNext.Click
PgNum += 1
bindrepeater()
End Sub
Protected Sub btnPrev_Click(sender As Object, e As System.EventArgs) Handles btnPrev.Click
PgNum -= 1
bindrepeater()
End Sub
Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
bindrepeater()
End Sub
我的问题是我的下一个按钮总是+2和前一个按钮-2。
谢谢