Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on 

Convert Datatable to Ilist

I have a RadGrid project that uses drag and drop with IList Data handling the data transfers.

My problem is that I need to populate one of the grids with data FIRST.  So...

My attached code will populate my grid using a datatable.

What I NEED to do is convert the Datatable to an IList named ShippedOrdersStore and use that as the datasource.
Protected Sub grdCollateral_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs)
        Dim objConn1 As SqlConnection
        objConn1 = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnPortal"))
        Dim oCom1 As SqlCommand
        oCom1 = New SqlCommand
        oCom1.Connection = objConn1
        oCom1.CommandText = "sp_cfa_TestCollateral"
        oCom1.CommandType = CommandType.StoredProcedure
        Dim dA As SqlDataAdapter = New SqlDataAdapter(oCom1)
        Dim myDataTable As DataTable = New DataTable()
        objConn1.Open()
        Try
            dA.Fill(myDataTable)
        Finally
            objConn1.Close()
        End Try
        grdCollateral.DataSource = myDataTable.DefaultView
        grdCollateral.GroupingSettings.CaseSensitive = False
        objConn1.Dispose()
        oCom1.Dispose()
        oCom1 = Nothing
    End Sub

Open in new window

.NET ProgrammingVisual Basic.NETMicrosoft Development

Avatar of undefined
Last Comment
Nasir Razzaq
Avatar of kovilpattiBalu
kovilpattiBalu
Flag of India image

hi,
here is ther code

public static IList<T> ConvertTo<T>(DataTable table)
    {
        if (table == null)
            return null;
 
        List<DataRow> rows = new List<DataRow>();
 
        foreach (DataRow row in table.Rows)
            rows.Add(row);
 
        return ConvertTo<T>(rows);
    }
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Larry Brister
Larry Brister
Flag of United States of America image

ASKER

Thanks
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Glad to help :-)
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo