Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Easiest way to bind a grid datasource to a datatable

Reply
Thread Tools

Easiest way to bind a grid datasource to a datatable

 
 
=?Utf-8?B?S2VubmV0aA==?=
Guest
Posts: n/a
 
      01-18-2004
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
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      01-18-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VubmV0aA==?=
Guest
Posts: n/a
 
      01-18-2004
Kiitos Teemu,

/Kenneth
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the easiest way to select top 20 rows from a datatable ? Ersin Gençtürk ASP .Net 7 06-28-2011 04:50 PM
What's the easiest way to create a grid with rowspan/colspan? gnewsgroup ASP .Net 2 02-03-2008 04:18 AM
Sort a datatable and create a new datatable Fredrik Rodin ASP .Net 3 09-28-2007 07:28 AM
Casting DataTable to class inherit from DataTable =?Utf-8?B?Qmx1ZWZsb3dlcg==?= ASP .Net 0 04-02-2004 05:41 AM
Adding DataTable Rows To another DataTable J. Babe ASP .Net 1 08-15-2003 05:04 PM



Advertisments