Hello friends,
I have some textboxs and 4 buttons as first,next, previous and last
.First all the data will be bound to the textbox at runtime.when I
will click the respective button I will get the result.
Thank you
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 14, 2011, 1:23 AM EDT
Try this.
Default.aspx code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Default.aspx.vb code
Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Shared sqlda As SqlDataAdapter
Shared com As SqlCommand
Shared ds As DataSet
Shared dt As DataTable
Shared dr As DataRow
Dim str As String
Shared r1, r2 As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
If Not IsPostBack Then
con.Open()
str = "select * from student"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
ds = New DataSet
sqlda.Fill(ds, "student")
dt = ds.Tables("student")
r1 = dt.Rows.Count
If r1 > 0 Then
showfirst()
End If
r2 = 0
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
con.Close()
bindgrid()
End Sub
Sub bindgrid()
con.Open()
str = "select * from student"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
ds = New DataSet
sqlda.Fill(ds, "student")
GridView1.DataSource = ds
GridView1.DataMember = "student"
GridView1.DataBind()
con.Close()
End Sub
Protected Sub btnfirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnfirst.Click
showfirst()
End Sub
Public Sub showfirst()
TextBox1.Text = dt.Rows(0).ItemArray(0)
TextBox2.Text = dt.Rows(0).ItemArray(1)
TextBox3.Text = dt.Rows(0).ItemArray(2)
TextBox4.Text = dt.Rows(0).ItemArray(3)
TextBox5.Text = dt.Rows(0).ItemArray(4)
End Sub
Protected Sub btnprevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnprevious.Click
Try
If r2 > 0 Then
r2 -= 1
TextBox1.Text = dt.Rows(r2).ItemArray(0)
TextBox2.Text = dt.Rows(r2).ItemArray(1)
TextBox3.Text = dt.Rows(r2).ItemArray(2)
TextBox4.Text = dt.Rows(r2).ItemArray(3)
TextBox5.Text = dt.Rows(r2).ItemArray(4)
End If
Catch ex As Exception
Response.Write(ex.Message)
Finally
con.Close()
End Try
End Sub
Protected Sub btnnext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnnext.Click
Try
If r2 < r1 Then
r2 += 1
TextBox1.Text = dt.Rows(r2).ItemArray(0)
TextBox2.Text = dt.Rows(r2).ItemArray(1)
TextBox3.Text = dt.Rows(r2).ItemArray(2)
TextBox4.Text = dt.Rows(r2).ItemArray(3)
TextBox5.Text = dt.Rows(r2).ItemArray(4)
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Protected Sub btnlast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnlast.Click
Try
TextBox1.Text = ds.Tables("student").Rows(r1 - 1).ItemArray(0)
TextBox2.Text = ds.Tables("student").Rows(r1 - 1).ItemArray(1)
TextBox3.Text = ds.Tables("student").Rows(r1 - 1).ItemArray(2)
TextBox4.Text = ds.Tables("student").Rows(r1 - 1).ItemArray(3)
TextBox5.Text = ds.Tables("student").Rows(r1 - 1).ItemArray(4)
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
End Class
Thanks
If this post helps you mark it as answer