Home SWOT Analysis How Strong U R? Articles About Us
Mahatma Gandhi Jawaharlal Nehru Bagat Singh Kamarajar Indira Gandhi

Oh Indian

In remembrance of the Independance day Aug 15, 2007

This site is dedicated to one and all who sincerely participated in freedom struggle. Let us try to fulfill their ambitions!
Skip Navigation Links

ASP.NET Listing of Records in Grid View


It is very simple to display the records in a Grid View.

  1. If you have not downloaded this project, download it and open it in Vistual Studio 2005 using Open Website option.
  2. Add a new form to the project and open it in design view.
  3. Place a grid view control in a form.
  4. Write the following highlighted code in the Code Module.
  5. Set the new form as the Startup form.
  6. Run the project to have a preview.
Imports System.Data
Partial Class GridViewList
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, _
		ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            LoadData()
        End If
    End Sub

    ' I strongly recommend to create a procedure
    ' LoadData to bind the grid view.
    ' Because we need to call this procedure from
    ' different places of the coding.
    Private Sub LoadData()
        Try
            Dim Sql As String
            ' Here you may extract records from any
            ' table from your database.
            Sql = "Select * From Users"
            Dim dt As DataTable
            dt = GetDataTable(Sql)

            ' These following code is importat to bind  
            ' the records to the Grid View.
            GridView1.DataSource = dt
            GridView1.DataBind()
        Catch ex As Exception
            ShowError(ex)
        End Try
    End Sub
End Class

You should get the output just like the one given below:
Sample Gridview Listing output
Comments from Users (1)
laminate flooring 01-Sep-2010 06:41:30 
Laminate flooring is an inexpensive type of flooring that offers the consumer many benefits and is relatively easy to install.
Before getting started here is a pro and a con of laminate flooring. Laminate flooring gives your floor that overall look of wood that can be enjoyed for years to come.
Leave a Reply
Name (Required)  
Mail (will not be published) (required)    
Website
 
Invalid Domain! (http://loveletters.oh-indian.com/blogs/20070909/30/asp-net-listing-of-records-in-grid-view.aspx) You are not allowed member of our Sites for link exchange!