By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,602 Members | 994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,602 IT Pros & Developers. It's quick & easy.

Easiest way to bind a grid datasource to a datatable

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Well,

all I can say is that you don't necessarily need to create the DataView
explicitly for databinding (binding happens to DataView, dt.DefaultView,
automatically if you provide the DataTable as data source)

e.g

grid.DataSource = dtTotal
grid.DataBind()

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Kenneth" <an*******@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
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

Nov 18 '05 #2

P: n/a
Kiitos Teemu,

/Kenneth
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.