How to bind textbox values to Gridview

Abstract:-
Just Drag and drop the 3 textbox,one button and gridview control to out page.

Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim Table As New DataTable("UserDetails")
Dim column As DataColumn
Dim dr As DataRow
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

column = New DataColumn
column.DataType = System.Type.GetType("System.String")
column.ColumnName = "Name"
column.Caption = "UserName"
Table.Columns.Add(column)
column = New DataColumn()
column.DataType = System.Type.GetType("System.String")
column.ColumnName = "Age"
column.Caption = "Age"
Table.Columns.Add(column)
column = New DataColumn()
column.DataType = System.Type.GetType("System.String")
column.ColumnName = "Location"
column.Caption = "Location"
Table.Columns.Add(column)


End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
dr = Table.NewRow()
dr("Name") = TextBox1.Text
dr("Age") = TextBox2.Text
dr("Location") = TextBox3.Text
Table.Rows.Add(dr)
GridView1.DataSource = Table
GridView1.DataBind()
End Sub
End Class

No comments:

Post a Comment

Plz Share your comments...