This is a migrated thread and some comments may be shown as answers.

Retrieving data from RadGrid and adding it to dataset

1 Answer 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Al Safavi
Top achievements
Rank 1
Al Safavi asked on 21 Aug 2008, 08:56 PM

Hi,
I am trying to retrieve data from a Rad Grid and inserting it into a dataset.
I am using the following code, but somehow it's not working.  I would appreciate it if you could tell me how I should get it to work.


Imports System.Data.SqlClient
Imports System.Data
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim dt As DataTable = New System.Data.DataTable("Parameters")
    Dim ds As New DataSet
    Dim column As DataColumn
    Dim row As DataRow

    column = New DataColumn
    column.DataType = System.Type.GetType("System.String")
    column.ColumnName = "ParameterID"
    column.Unique = True
    dt.Columns.Add(column)

    column = New DataColumn
    column.DataType = System.Type.GetType("System.String")
    column.ColumnName = "ParameterDesc"
    column.Unique = True
    dt.Columns.Add(column)

    Dim PrimaryKeyColumns(0) As DataColumn
    PrimaryKeyColumns(0) = dt.Columns("ParameterID")
    dt.PrimaryKey = PrimaryKeyColumns

    ds.Tables.Add(dt)

    For Each Item In RadGrid1.MasterTableView.Items
        row = dt.NewRow
        row("ParameterID") = Item.Cells(0).Text
        row("ParameterDesc") = Item.Cells(1).Text
        dt.Rows.Add(row)
    Next
End Sub


Thank you,
Al

1 Answer, 1 is accepted

Sort by
0
Kiara
Top achievements
Rank 1
answered on 22 Aug 2008, 02:22 PM
Al, the safe solution is to access the cells in the grid using the unique name of the column and then fetch the data from them. Review these resouces for further details on this approach:

http://www.telerik.com/demos/aspnet/prometheus/Grid/Examples/Programming/AccessingCellsAndRows/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

Kiara
Tags
Grid
Asked by
Al Safavi
Top achievements
Rank 1
Answers by
Kiara
Top achievements
Rank 1
Share this question
or