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

Virtualization with Datatable

3 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yo
Top achievements
Rank 1
Yo asked on 18 Dec 2013, 10:28 AM
Hi,
    I want to implement the virtualization of the grid which bind with the dataTable but don't know to achieve it.
    In your existing virtualization sample which the grid is binding with a List of Object. Is it possible to bind it with Datatable ?
   
Please advise..

Thanks a lot.
Don.,

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Dec 2013, 11:33 AM
Hi,

Please have a look into the below sample code snippet that binds data to RadGrid using DataTable.

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
    SqlConnection conn = new SqlConnection(ConnString);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand("SELECT * FROM Orders", conn);
    DataTable myDataTable = new DataTable();
    conn.Open();
    try
    {
        adapter.Fill(myDataTable);
    }
    finally
    {
        conn.Close();
    }
    RadGrid1.DataSource = myDataTable;
}

Thanks,
Princy
0
Yo
Top achievements
Rank 1
answered on 19 Dec 2013, 02:02 AM
Hi,
   Thank you for your answer. 
    In fact, I do know how's the Grid to bind with the datatable but I just don't know how it implement with the Virtualization (The infinity scrolling function).
    Please advise, Thanks a lot..

Don.,
0
Princy
Top achievements
Rank 2
answered on 19 Dec 2013, 08:45 AM
Hi ,

Below is a sample code snippet that i tried using DataTable to bind the RadGrid.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" AllowPaging="true" PageSize="1000"
    AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource">
        <ClientSettings ReorderColumnsOnClient="true" AllowColumnsReorder="true" ColumnsReorderMethod="Reorder">
        <Virtualization EnableVirtualization="true" InitiallyCachedItemsCount="2000" ItemsPerView="100"/>
        <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="500px" />
        <Resizing AllowColumnResize="true" />
    </ClientSettings>
</telerik:RadGrid>

C#:
int i;
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable dt = new DataTable();
    dt.Columns.Add("Column", typeof(string));
    dt.Columns.Add("Date", typeof(DateTime));
    for (i = 0; i < 300000; i++)
    {
        dt.Rows.Add("Row" + i, DateTime.Now.AddDays(i));
    }
    RadGrid1.DataSource = dt;
}

Thanks,
Princy
Tags
Grid
Asked by
Yo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Yo
Top achievements
Rank 1
Share this question
or