Creating Table and binding to Datagrid vb asp.net 2.0

Monday, October 12, 2015 Unknown 4 Comments

Here is an example of binding a table to a datagrid

'First you need to create the table.

Dim Row As DataRow
'declaring three rows for the table
Dim img As DataColumn = New DataColumn("Img")
img.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(img)
Dim Name As DataColumn = New DataColumn("Name")
'declaring a column named Name
Name.DataType = System.Type.GetType("System.String")
'setting the datatype for the column
Table1.Columns.Add(Name)
'adding the column to table
Dim Price As DataColumn = New DataColumn("Price")
Price.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Price)
Dim Click As DataColumn = New DataColumn("Click")
Click.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Click)


Lenovo announcing Windows Vista!


'now add your information to the table.

Try
For j = 0 To productResult.products.Length - 1
'creating a table named Customers

Row = Table1.NewRow()
'declaring a new row
'insert image in table
Row.Item("Img") = ""
Row.Item("Name") = productResult.products(j).name
'filling the row with values. Item property is used to set the field value.
Row.Item("Price") = productResult.products(j).price.ToString
'filling the row with values. adding a product
'insert href in table
Row.Item("Click") = "More Information"
'filling the row with values. adding a location
Table1.Rows.Add(Row)
'adding the completed row to the table

Next
Catch ex As Exception
'test.Text = "Sorry No Products are currently available!"
End Try

'create dataset and add table to it
Dim ds As New DataSet
ds = New DataSet
'creating a dataset
ds.Tables.Add(Table1)
'adding the table to dataset
DataGrid1.DataSource = ds.Tables("Products")
DataGrid1.DataBind()
'binding the table to datagrid





4 comments :

  1. hydrocodone..try it?
    Are you having an issue.. if so.. I can explain it!
    GEEKDAD

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete

Powered by Blogger.