0

コードを変更しました。アップデートパネルとリンクボタンを追加します

マークアップ

 <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を追加して、データをリピーターにバインドします

 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になることです。

ありがとうございました

4

0 に答える 0