更新时间:2023-12-01 19:57:40
在这个类似的问题上参考我的常见答案,但它是用C#编写的,试着理解逻辑和在你的应用程序中实现
第一个下一个上一个按钮的代码和页面窗口中的显示数据C#application [ ^ ]
使用它将c#转换为VB CodeTranslator:从c#到VB的代码翻译 [ ^ ]
I have 4 buttons (Next,Previous,First,Last) which moves through the rows of a datatable.
The buttons First and Last are working correctly but the other buttons are not(nothing happens if i press them,they keep pointing to record 1).
When i press the Last button it goes to the last record,but when i press the next button it takes me to the first record instead of telling me "No more Records".
This is a pic of my form: Form
This is my code Below and the form code:
What I have tried:
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Partial Class P3
Inherits System.Web.UI.Page
Dim ds As New DataSet
Dim inc As Integer
Dim MaxRows As Integer
Dim tbl As DataTable
Private Sub NavigateRecords()
Gidbx.Text = tbl.Rows(inc).Item(0)
Gnamebx.Text = tbl.Rows(inc).Item(1)
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Response.Write(Session("slctdGarage"))
Dim strConnectionString As String
Dim instsqlconnection As SqlConnection
strConnectionString = "Integrated Security=SSPI;Initial Catalog=MySetOfGarages;Data Source=."
instsqlconnection = New SqlConnection(strConnectionString)
instsqlconnection.Open()
Dim da As New SqlDataAdapter("Select * From Garage", instsqlconnection)
da.Fill(ds, "Grg")
tbl = ds.Tables("Grg")
instsqlconnection.Close()
MaxRows = tbl.Rows.Count
inc = -1
End Sub
Protected Sub Nextrec_Click(sender As Object, e As EventArgs) Handles Nextrec.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
Response.Write("No More Rows")
End If
End Sub
Protected Sub Previousrec_Click(sender As Object, e As EventArgs) Handles Previousrec.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
ElseIf inc = -1 Then
Response.Write("No Records Yet")
ElseIf inc = 0 Then
Response.Write("First Record")
End If
End Sub
Protected Sub Lastrec_Click(sender As Object, e As EventArgs) Handles Lastrec.Click
If inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If
End Sub
Protected Sub Firstrec_Click(sender As Object, e As EventArgs) Handles Firstrec.Click
If inc <> 0 Then
inc = 0
NavigateRecords()
End If
End Sub
End Class
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="P3.aspx.vb" Inherits="P3" %>
<form id="form1" runat="server">
<p>
id Garage
<asp:TextBox ID="Gidbx" runat="server"></asp:TextBox>
</p>
<p>
GarageName
<asp:TextBox ID="Gnamebx" runat="server"></asp:TextBox>
<asp:Button ID="Firstrec" runat="server" Text="<<" />
<asp:Button ID="Previousrec" runat="server" Text="<" />
<asp:Button ID="Nextrec" runat="server" Text=">" />
<asp:Button ID="Lastrec" runat="server" Text=">>" />
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Add Record" />
<asp:Button ID="Button2" runat="server" Text="Update Rec" />
<asp:Button ID="Button3" runat="server" Text="Delete Rec" />
</p>
</form>
refer my prev answer on this similar question, but it was written on C#, try to understand the logic and implement in your app
Code for first next last previous button and display data in page windows C# application[^]
use this for converting the c# to VB CodeTranslator: Code Translation From c# to VB [^]