Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Binding DataGrid to Array


Binding DataGrid to Array

Reply
  #1 (permalink)  
Old 10-31-03, 09:38 AM
petersza petersza is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Binding DataGrid to Array

Does anyone have code, or know where I can find some, or can explain how to bind a DataGrid to an Array?

Thank you,

p
Reply With Quote
  #2 (permalink)  
Old 11-15-04, 01:06 PM
thuenb thuenb is offline
Newbie Coder
 
Join Date: Oct 2004
Location: MI
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Turn Array Into Dataset Then populate into Grid...

Following are the code functions and subs you will need...

Functions to create dataset and rows...
Code:
  Private Function CreateDataSet() As DataSet
        Dim ds As DataSet = New DataSet("Messages")
        ds.Tables.Add(CreateMyTable)
        Return ds
    End Function

    Private Function CreateMyTable() As DataTable
        Dim SearchResults As DataTable = New DataTable("SearchResults")
        SearchResults.Columns.Add(New DataColumn("ItemID", GetType(Integer)))
        SearchResults.Columns.Add(New DataColumn("Name", GetType(String)))
        SearchResults.Columns.Add(New DataColumn("LongDesc", GetType(String)))
        SearchResults.Columns.Add(New DataColumn("ShortDesc", GetType(String)))
        SearchResults.Columns.Add(New DataColumn("Image", GetType(String)))
        Return SearchResults
    End Function
Sub Routine to add row of data to dataset:
Code:
 Dim myDataset As DataSet = CreateDataSet()
'Add a loop here
Do while loop = true
                    Dim dataRow As dataRow = myDataset.Tables("SearchResults").NewRow
                    dataRow("ItemID") = Array(0)
                    dataRow("Name") = Array(1)
                    dataRow("LongDesc") = Array(2)
                    dataRow("ShortDesc") = Array(3)
                    dataRow("Image") = Array(4)
                    myDataset.Tables("SearchResults").Rows.Add(dataRow)
end loop
Then you will want to bind the dataset to the datagrid....
Code:
Dim myDataView As New DataView()
            myDataView.Table = myDataset.Tables("SearchResults")
            MydataGrid.CurrentPageIndex = 0
            MydataGrid.DataSource = myDataView
            MydataGrid.DataBind()
Hope this helps
__________________
Best Regards,
Brian Thuen
http://www.AdvisedSolutions.com

Last edited by thuenb; 11-15-04 at 01:11 PM.
Reply With Quote
Reply

Bookmarks

« Help | Migrating »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional Array Sorting Kage PHP 6 12-12-05 04:19 PM
newbie perl script to call an array in a subroutine and add 1 Arowana Perl 1 10-31-03 01:04 PM
move array element up or down Perry JavaScript 4 09-27-03 04:23 PM
passing array to hidden fields in form on next page? seala ASP 2 09-04-03 02:40 PM
asp: values in array not in order?? seala ASP 0 08-16-03 12:06 PM


All times are GMT -5. The time now is 01:14 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.