Show Grid View in ASP. NET using VB.NET

In this article we will learn to show gridview in
  • 2016

Show Grid View in VB.Net

  1. Create a new website in visual studio 2005/2008.
  2. Select a file location and file name and language.
  3. Create some text boxes with name in web form.



    Now drag a grid view in web form and click the edit column property  show in figure and add the item inside the grid view .You can also change it format by using property Auto Format.


    Now choose the data source and click on ok button.


    Now click on New Connection and then click on


    Choose either Window or server authentication, server name and attach the database. Click on ok button

    Now Click next



    Further Click next


    Click next and test Query and click finish


    Now use the Defalut.aspx.vb page and add the following code

    Imports System.Data.SqlClient

    Partial Class _Default

        Inherits System.Web.UI.Page
        Dim con As SqlConnection
        Dim cmd As SqlCommand
        Dim str As String
        Dim ad As SqlDataAdapter
        Dim dr As SqlDataReader

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

            con = New SqlConnection("Data Source =MCNDESKTOP06; Initial catalog = empinfo ; User ID = sa;Password = wintellect")

            str = (("select * from emp_info where name ='" + TextBox1.Text & "' ,address = '") + TextBox2.Text & "',email_id ='") + TextBox3.Text & "'"
            ad = New SqlDataAdapter(str, con)
            ad.Fill(ds, "emp_info")
            GridView1.DataSource = ds.tables(emp_info).defaultview
            GridView1.DataMember = "emp_info"

        End Sub


More Articles

© 2020 DotNetHeaven. All rights reserved.