Loading a datagrid

  • Thread starter Thread starter Tim Marsden
  • Start date Start date
T

Tim Marsden

Hi,

I want to display the contents of a table in a datagrid. However I don't
want to load all the rows before presenting it to the user. Is there a way I
can load the datagrid a page at a time, load the next page as the user
scrolls down.

Tim
 
Hi Tim,

You can use the Fliter method on the DataTable's primary key column. e.g.
Filter top 100 records on the primary key column and bind these to the
DataGrid. When you want to show next set of records, modify the filter
accordingly and bind again.

Or, you can modify the SQL query and fetch records between a certain row
number. Again, when you want to show the next set of records, modify the row
number range in the query, refetch and rebind.

Let me know if this was helpful.

-Prateek

Hi,

I want to display the contents of a table in a datagrid. However I don't
want to load all the rows before presenting it to the user. Is there a way I
can load the datagrid a page at a time, load the next page as the user
scrolls down.

Tim
 
Hi Tim,

I agree with Prateek that you can filter the records. In ADO.NET, you can
use the DataView.RowFilter property and the DataTable.Select method to
filter a subset of records. Please refer to the following articles and
samples for detailed information on this subject:

Filtering and Sorting in ADO.NET
http://www.akadia.com/services/dotnet_filter_sort.html

HOW TO: Perform a Complex Filter in ADO.NET
http://support.microsoft.com/?id=321896

Please feel free to let me know if you have any problems or concerns.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi
Thanks for the response,

I only want to fetch the minimal amount of data from the database. Is it the
case with ADO that I have to populate the whole of the datatable before
applying the filter?. This defeats the object of trying to improve
performance.

Tim.
 
Yes, in this scenario you will need to fill the whole DataTable.

If you dont want to populate the whole datatable, then use my second option.
i.e. fetch only certain number of records each time.

e.g. if you have a table called MyTable and a PK field called ID which runs
from say 10000 to 12000 AND you want to show only 100 records each time
then,

iMin = 10000
iMax = 10100
SQL = "select * from MyTable where ID >= " & iMin & " and ID <= " & iMax
'Fill the datatable using this statement

'Now when you want show the next page

iMin = iMin + 100
iMax = iMax + 100

SQL = "select * from MyTable where ID >= " & iMin & " and ID <= " & iMax
'Fill the datatable using this statement


Hope this helps

- Prateek


Hi
Thanks for the response,

I only want to fetch the minimal amount of data from the database. Is it the
case with ADO that I have to populate the whole of the datatable before
applying the filter?. This defeats the object of trying to improve
performance.

Tim.
 
Back
Top