2 Replies - 230 Views - Last Post: 29 December 2017 - 12:13 AM Rate Topic: -----

#1 nirmal.c  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-December 17

data from text box to gridview

Posted 27 December 2017 - 09:54 PM

Imports System.Data
    Partial Class _Default
    Inherits System.Web.UI.Page
   
 Dim dt As New DataTable

     Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    dt.Columns.Add("num")
    dt.Columns.Add("emailid")
    
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      dt.Rows.Add(TextBox1.Text, TextBox2.Text)
        [new].DataSource = dt
        [new].DataBind()
        
  End Sub
  End Class




i have done this code to print data from textbox to gridview

but i want to print more number of data,every time i click sumbit button the data should be printed in new row.

can anybody help me out of this??

This post has been edited by andrewsw: 28 December 2017 - 12:25 AM
Reason for edit:: added missing [code][/code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: data from text box to gridview

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5121
  • View blog
  • Posts: 13,790
  • Joined: 18-April 07

Re: data from text box to gridview

Posted 28 December 2017 - 10:37 AM

If you call "NewRow" on your datatable object, you can get an instance of a datarow, with that you can add multiple values and such, that you then add to your datatable with Add. Here is a really good page to show you the process...

https://docs.microso...framework-4.7.1

Be sure to select "VB" from the drop down on the right to see the VB.NET version of the code. This should help quite a bit for you to scale up what you have going there. My suggestion would be to create a new function which will build your rows for you and then returns a new row. That way you can pass it some values, it returns a new datarow and then you add it to the datatable.

:)
Was This Post Helpful? 0
  • +
  • -

#3 nirmal.c  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-December 17

Re: data from text box to gridview

Posted 29 December 2017 - 12:13 AM

View PostMartyr2, on 28 December 2017 - 10:37 AM, said:

If you call "NewRow" on your datatable object, you can get an instance of a datarow, with that you can add multiple values and such, that you then add to your datatable with Add. Here is a really good page to show you the process...

https://docs.microso...framework-4.7.1

Be sure to select "VB" from the drop down on the right to see the VB.NET version of the code. This should help quite a bit for you to scale up what you have going there. My suggestion would be to create a new function which will build your rows for you and then returns a new row. That way you can pass it some values, it returns a new datarow and then you add it to the datatable.

:)/>





thanks for the reply
i have done the code.but the same data is printed 10 times
everytime i enter a new data in textbox it should be printed in gridview in a new row.can u help me with this



Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim table As DataTable = New DataTable()
Dim column As DataColumn
Dim row As DataRow
Dim view As DataView

' Create new DataColumn, set DataType, ColumnName and add to DataTable.
column = New DataColumn()
column.DataType = System.Type.GetType("System.Int32")
column.ColumnName = "id"
table.Columns.Add(column)

' Create second column.
column = New DataColumn()
column.DataType = Type.GetType("System.String")
column.ColumnName = "item"
table.Columns.Add(column)

' Create new DataRow objects and add to DataTable.
Dim i As Integer
For i = 0 To 9
row = table.NewRow()
row("id") = TextBox1.Text
row("item") = TextBox2.Text
table.Rows.Add(row)
Next
' Create a DataView using the DataTable.
view = New DataView(table)

' Set a DataGrid control's DataSource to the DataView.
GridView1.DataSource = view
GridView1.DataBind()
End Sub
End Class
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1