G
Guest
Hi,
I want to make sure I got the easiest way on how to bind a grid's datasource to a datatable.
I've made an in-memory datatable
Dim dtTotal As DataTable
Dim drow As DataRow
dtTotal = New DataTable("Total")
' Add two columns
dcol = dtTotal.Columns.Add("Str1", System.Type.GetType("System.String"))
dcol = dtTotal.Columns.Add("Dec1", System.Type.GetType("System.Decimal"))
' Add two rows
drow = dtTotal.NewRow()
drow("Str1") = "The first value"
drow("Dec1") = 1001
dtTotal.Rows.Add(drow)
drow = dtTotal.NewRow()
drow("Str1") = "The second value"
drow("Dec1") = 1002
dtTotal.Rows.Add(drow)
As I understand, you only should need to create a dataview object and bind it to a grid's datasource
Dim dv As DataView
dv = dtTotal.DefaultView
grid.DataSource = dv
grid.DataBind()
Is this the easiest way or the way with least resources on the server?
/Kenneth
I want to make sure I got the easiest way on how to bind a grid's datasource to a datatable.
I've made an in-memory datatable
Dim dtTotal As DataTable
Dim drow As DataRow
dtTotal = New DataTable("Total")
' Add two columns
dcol = dtTotal.Columns.Add("Str1", System.Type.GetType("System.String"))
dcol = dtTotal.Columns.Add("Dec1", System.Type.GetType("System.Decimal"))
' Add two rows
drow = dtTotal.NewRow()
drow("Str1") = "The first value"
drow("Dec1") = 1001
dtTotal.Rows.Add(drow)
drow = dtTotal.NewRow()
drow("Str1") = "The second value"
drow("Dec1") = 1002
dtTotal.Rows.Add(drow)
As I understand, you only should need to create a dataview object and bind it to a grid's datasource
Dim dv As DataView
dv = dtTotal.DefaultView
grid.DataSource = dv
grid.DataBind()
Is this the easiest way or the way with least resources on the server?
/Kenneth