How to show empty Gridview using ASP.Net

How to show Empty gridview?

Just create the Datatable and bind it to Gridview control.

Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim dtrow As DataRow
Dim dtNewTable As New DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dtcol, dtcol1 As New DataColumn
dtcol.DataType = System.Type.GetType("System.String")
dtcol.ColumnName = "Emp ID"
dtNewTable.Columns.Add(dtcol)
dtcol1.DataType = System.Type.GetType("System.String")
dtcol1.ColumnName = "Emp Name"
dtNewTable.Columns.Add(dtcol1)
Dim i As Integer
For i = 0 To 4
dtrow = dtNewTable.NewRow()
dtrow("Emp ID") = ""
dtrow("Emp Name") = ""
dtNewTable.Rows.Add(dtrow)
Next i
GridView1.DataSource = dtNewTable
GridView1.DataBind()
End Sub
End Class

No comments:

Post a Comment

Plz Share your comments...