Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Populating DataGrid

Reply
Thread Tools

Populating DataGrid

 
 
vbGansta
Guest
Posts: n/a
 
      01-22-2004
Hi there!!

Sorry for the simplicity of this one, but I am just getting my feet wet in
this. How do I populate a data control manually from code? In other words
I want to fill it myself not have it bound to a back end database. Is there
another control that would better suit this? Any code examples would be
awesome.

Thanks,

Joe


 
Reply With Quote
 
 
 
 
ONIL@
Guest
Posts: n/a
 
      01-23-2004

Hi vbGansta !

You can use a DataTable like this :

Dim dt As DataTable

Dim dr As DataRow

Dim i As Integer

'create a DataTable

dt = New DataTable

dt.Columns.Add(New DataColumn("Name", GetType(String)))

dt.Columns.Add(New DataColumn("First.", GetType(String)))

dt.Columns.Add(New DataColumn("Last", GetType(String)))

'Make the rows and add data.

For i = 1 To 12

dr = dt.NewRow()

dr(0)= "Hi " & i+1
dr(1) = "Hi" & i+2


dr(2) = "Hi" & i+3

'add each row to the DATATABLE

dt.Rows.Add(dr)

Next

dr = dt.NewRow()

dt.Rows.Add(dr)

DataGrid1.DataSource = new DataView(dt)

DataGrid1.DataBind

I hope it helps
Best Regards
--
ONil@.
MX.




--
ONil@.
MX.

"vbGansta" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi there!!
>
> Sorry for the simplicity of this one, but I am just getting my feet wet in
> this. How do I populate a data control manually from code? In other

words
> I want to fill it myself not have it bound to a back end database. Is

there
> another control that would better suit this? Any code examples would be
> awesome.
>
> Thanks,
>
> Joe
>
>



 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      01-24-2004
Here's some code that I use, adapted from the VS.NET documentation.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub
Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add _
(New DataColumn("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = True
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource

"vbGansta" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi there!!
>
> Sorry for the simplicity of this one, but I am just getting my feet wet in
> this. How do I populate a data control manually from code? In other
> words
> I want to fill it myself not have it bound to a back end database. Is
> there
> another control that would better suit this? Any code examples would be
> awesome.
>
> Thanks,
>
> Joe
>
>


 
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
Populating a DataGrid Bob Hollness ASP .Net 4 01-12-2005 07:43 PM
Populating a datagrid ... how is it done normally? Prime ASP .Net 2 10-01-2004 01:35 AM
Datagrid Dropdown not populating =?Utf-8?B?VGltOjouLg==?= ASP .Net 1 08-20-2004 01:39 PM
Timeout on populating a datagrid Paul ASP .Net 4 05-05-2004 06:36 PM
Populating a datagrid from two separate data sources John ASP .Net 1 07-31-2003 06:46 AM



Advertisments