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

display large data with gridview

1 Answer 383 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Charlie
Top achievements
Rank 1
Charlie asked on 23 Dec 2008, 06:18 PM
Hi,

    I am trying to use radGridView to display large amount of data records (200,000+ records). The radGridView just hangs and load it for a long time. How do I make it so that radGridview can display the data as it loads the rest of the data (like the SQL server management studio). Thank you in advance for your help.

I've the sample code below:

private bool BindToDataReader(string query)
        {
            this.radGridView1.MasterGridViewTemplate.AllowAddNewRow = false;
            this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = true;
            this.radGridView1.MasterGridViewTemplate.EnableGrouping = true;
            this.radGridView1.GridElement.BeginUpdate();
            SqlCommand command = new SqlCommand(query);
            command.CommandTimeout = 0;
            command.Connection = new SqlConnection(_strConnection);
            try
            {
                command.Connection.Open();
                this.radGridView1.MasterGridViewTemplate.LoadFrom(command.ExecuteReader());
                command.Connection.Close();
                for (int i = 0; i < radGridView1.MasterGridViewTemplate.Columns.Count; i++)
                {
                    this.radGridView1.MasterGridViewTemplate.Columns[i].Width = 102;
                }
                this.radGridView1.GridElement.EndUpdate();
            }
            catch (Exception ex){
                objLogger.Trace(ex.StackTrace.ToString() + Environment.NewLine + ex.Message.ToString());
                return false;
            }
            return true;
        }

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 29 Dec 2008, 02:59 PM
Hi Charlie,

Thank you for writing.

When you are loading a large amount of data you can experience delay, and this was because in such of scenario you have to load all of the information in the memory. This is not a problem with RadGridView rather of disconnected model of database manipulation.

To avoid this and fetch only portion of data that currently displayed you can use Virtual mode of RadGridView. With virtual mode, you can implement your own data management operations. When you are implementing virtual mode, you will need to track when a new row is needed in the data model and when to rollback the addition of the new row. The exact implementation of this functionality will depend on the implementation of the data model and the transaction semantics of the data model; whether commit scope is at the cell or row level.

With virtual mode, you can manage the interaction between the RadGridView control and a custom data cache. To implement virtual mode, set the VirtualMode property to true and handle one or more of the following events:
 - CellValueNeeded
 - CellValuePushed
 - NewRowNeeded
 - RowDirtyStateNeeded
 - CancelRowEdit

You will typically handle at least the CellValueNeeded event, which enables the control look up values in the data cache. You can find some example code in our help documentation.

Do not hesitate to contact me again if you have other questions.

Greetings,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Charlie
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or