Featured Post

Step Wise Project Planning

Planning is the most difficult process in project management. The framework described is called the Stepwise method to help to distinguis...

  1. Home

Viewing a paged dataset with the new GridView server control in vb

 Imports System.Data.SqlClient

Imports System.Data


Partial Class _Default

    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            BindData()

        End If

    End Sub


    Private Sub BindData()

        Dim connectionString As String = "Your_Connection_String_Here"

        Dim query As String = "SELECT * FROM YourTable"


        Using connection As New SqlConnection(connectionString)

            Using command As New SqlCommand(query, connection)

                Dim adapter As New SqlDataAdapter(command)

                Dim dataTable As New DataTable()

                adapter.Fill(dataTable)


                GridView1.DataSource = dataTable

                GridView1.DataBind()

            End Using

        End Using

    End Sub

End Class

=========================================================================

In this example:

  1. The BindData method is called in the Page_Load event handler to populate the GridView with data when the page is first loaded.

  2. The BindData method establishes a connection to the database, executes the SQL query to fetch data, fills the retrieved data into a DataTable, sets the DataTable as the DataSource of the GridView, and finally binds the GridView to display the data.

Ensure to replace "Your_Connection_String_Here" with your actual database connection string, and "YourTable" with the name of your database table. Adjust the SQL query as needed to fetch the desired data from your database.

Previous
Next Post »