473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

custom paging w/ dynamic fields

The default paging behavior of the gridview doesn't work well with very large
sets of data which means we have to implement some sort of custom paging.
The examples I have seen (4guysfromrolla, etc.) suggest using an
ObjectDataSource which has built-in paging functionality that, when used in
conjunction with certain SQL 2005 functionality, only works with the records
to be displayed on the page rather than the entire set. The problem with
using the objectdatasource, for us, is that our users have the ability to
select the fields they want to see, which means we don't know what fields
will be present at design time.

Does anyone have a solution for when the grid fields will be dynamic?

Thanks in advance
May 17 '07 #1
7 2307

"Jeff Beem" <Je******@discussions.microsoft.comwrote in message
news:BA**********************************@microsof t.com...
The default paging behavior of the gridview doesn't work well with very
large
sets of data which means we have to implement some sort of custom paging.
The examples I have seen (4guysfromrolla, etc.) suggest using an
ObjectDataSource which has built-in paging functionality that, when used
in
conjunction with certain SQL 2005 functionality, only works with the
records
to be displayed on the page rather than the entire set. The problem with
using the objectdatasource, for us, is that our users have the ability to
select the fields they want to see, which means we don't know what fields
will be present at design time.

Does anyone have a solution for when the grid fields will be dynamic?

Thanks in advance
Hi Jeff

I think, you can try to do the data paging on the server using SQL Server
2005's new ROW_NUMBER() feature (in a stored procedure). If you have not
that many fields, you can return all of the fields for each page and bind to
a datagrid selected fields only.

With MyDocs AS (
SELECT *
ROW_NUMBER() OVER (order by 'sortcolumn') as RowNumber
FROM AllDocs )
select *
from MyDocs
Where RowNumber Between 1 and 10

There are many articles on this topic available in the Internet
http://www.google.com/search?hl=en&q...paging+asp.net

Hope it helps
May 17 '07 #2
Hello Alexey,

This is the approach mentioned in several of the articles I have seen. The
problem is that you still have to somehow tell the gridview the
virtualrecordcount so that it creates the correct number of page links. This
is why they're using the ObjectDataSource, as it supports the
virtualrecordcount, in those articles. Problem with binding to objects,
though, is that the fields we need to bind to are decided at runtime. We
already have the stored procedures that will return the correct records based
on the current page, etc. The problem is getting the paging to show on the
grid. If we don't use the ObjectDataSource all we get is one page, because
there appears to be no way to set the virtualrecordcount.

Thanks,

Jeff

"Alexey Smirnov" wrote:
>
"Jeff Beem" <Je******@discussions.microsoft.comwrote in message
news:BA**********************************@microsof t.com...
The default paging behavior of the gridview doesn't work well with very
large
sets of data which means we have to implement some sort of custom paging.
The examples I have seen (4guysfromrolla, etc.) suggest using an
ObjectDataSource which has built-in paging functionality that, when used
in
conjunction with certain SQL 2005 functionality, only works with the
records
to be displayed on the page rather than the entire set. The problem with
using the objectdatasource, for us, is that our users have the ability to
select the fields they want to see, which means we don't know what fields
will be present at design time.

Does anyone have a solution for when the grid fields will be dynamic?

Thanks in advance

Hi Jeff

I think, you can try to do the data paging on the server using SQL Server
2005's new ROW_NUMBER() feature (in a stored procedure). If you have not
that many fields, you can return all of the fields for each page and bind to
a datagrid selected fields only.

With MyDocs AS (
SELECT *
ROW_NUMBER() OVER (order by 'sortcolumn') as RowNumber
FROM AllDocs )
select *
from MyDocs
Where RowNumber Between 1 and 10

There are many articles on this topic available in the Internet
http://www.google.com/search?hl=en&q...paging+asp.net

Hope it helps
May 17 '07 #3

"Jeff Beem" <Je******@discussions.microsoft.comwrote in message
news:C8**********************************@microsof t.com...
Hello Alexey,

This is the approach mentioned in several of the articles I have seen.
The
problem is that you still have to somehow tell the gridview the
virtualrecordcount so that it creates the correct number of page links.
This
is why they're using the ObjectDataSource, as it supports the
virtualrecordcount, in those articles. Problem with binding to objects,
though, is that the fields we need to bind to are decided at runtime. We
already have the stored procedures that will return the correct records
based
on the current page, etc. The problem is getting the paging to show on
the
grid. If we don't use the ObjectDataSource all we get is one page,
because
there appears to be no way to set the virtualrecordcount.
In the case of custom paging you cannot use the built-in navigation, you
will need a custom navigation. Your stored procedure must return a total
number of the found rows. This number can be used to calculate how many
pages do you have (~ total \ gridview.Items.Count)

http://dotnetjunkies.com/Tutorial/EA...B871F967F.dcik

How do you select the fields you want to see? Maybe your problem is in just
in the select statement
May 17 '07 #4
Hi Alexey,

The fields are returned correctly from the stored procedure, that is not the
problem. The problem is that the gridview doesn't support setting a
virtualrecordcount so that it shows the correct number of pages (for example,
if I return the first 10 records but I knoew I have 10,000, I need to have
the gridview show the page numbers, etc. that indicate there are more pages).
The DataGrid supports this, from what I've been told, and we're considering
changing to use that, but we were hoping to find a solution using the
GridView.

"Alexey Smirnov" wrote:
>
"Jeff Beem" <Je******@discussions.microsoft.comwrote in message
news:C8**********************************@microsof t.com...
Hello Alexey,

This is the approach mentioned in several of the articles I have seen.
The
problem is that you still have to somehow tell the gridview the
virtualrecordcount so that it creates the correct number of page links.
This
is why they're using the ObjectDataSource, as it supports the
virtualrecordcount, in those articles. Problem with binding to objects,
though, is that the fields we need to bind to are decided at runtime. We
already have the stored procedures that will return the correct records
based
on the current page, etc. The problem is getting the paging to show on
the
grid. If we don't use the ObjectDataSource all we get is one page,
because
there appears to be no way to set the virtualrecordcount.

In the case of custom paging you cannot use the built-in navigation, you
will need a custom navigation. Your stored procedure must return a total
number of the found rows. This number can be used to calculate how many
pages do you have (~ total \ gridview.Items.Count)

http://dotnetjunkies.com/Tutorial/EA...B871F967F.dcik

How do you select the fields you want to see? Maybe your problem is in just
in the select statement
May 17 '07 #5

"Jeff Beem" <Je******@discussions.microsoft.comwrote in message
news:48**********************************@microsof t.com...
Hi Alexey,

The fields are returned correctly from the stored procedure, that is not
the
problem. The problem is that the gridview doesn't support setting a
virtualrecordcount so that it shows the correct number of pages (for
example,
if I return the first 10 records but I knoew I have 10,000, I need to have
the gridview show the page numbers, etc. that indicate there are more
pages).
The ObjectDataSource has a SelectCountMethod method which tells the gridview
how many rows are expected.

<asp:ObjectDataSource SelectCountMethod="GetTotalNumber"...

public int GetTotalNumber()
{
using (SqlConnection conn =
new SqlConnection(ConnectionString))
{
using (SqlCommand cmd =
conn.CreateCommand())
{
cmd.CommandText = "select count(*) from ...;
conn.Open();
return = (int)cmd.ExecuteScalar();
}
}
}

GridView Examples for ASP.NET 2.0: Paging and Sorting the GridView's Data
http://msdn2.microsoft.com/en-us/library/aa479347.aspx
May 17 '07 #6
Hi Alexey,

I realize the ObjectDataSource supports this. My question is how do I
create an object that has the dynamic fields? For example, let's say I have
a "Document" object that has a "DocumentId" property. That much is static,
it will always have that property. However, the user can select that they
want to also see "Author", "LastSavedDate", "WordCount", etc. out of a list
of potentially thousands of fields. Now, the stored procedure we have will
return a dataset that has those fields (field1=DocumentId, field2=Author,
field3=LastSavedDate, etc.) But I don't have an object that has those
fields/properties. I agree that the ObjectDataSource is a good solution for
custom paging. What I don't understand is how to get it to work with a set
of fields that I won't know until runtime.

I read an article about using Reflection.Emit and dynamic properties to add
properties to an existing object. However, since I have very little time
and I do not know that the databinding would even recognize these virtual
properties, I don't really want to spend the time investigating.

Any thoughts?

Thanks,

Jeff

"Alexey Smirnov" wrote:
>
"Jeff Beem" <Je******@discussions.microsoft.comwrote in message
news:48**********************************@microsof t.com...
Hi Alexey,

The fields are returned correctly from the stored procedure, that is not
the
problem. The problem is that the gridview doesn't support setting a
virtualrecordcount so that it shows the correct number of pages (for
example,
if I return the first 10 records but I knoew I have 10,000, I need to have
the gridview show the page numbers, etc. that indicate there are more
pages).

The ObjectDataSource has a SelectCountMethod method which tells the gridview
how many rows are expected.

<asp:ObjectDataSource SelectCountMethod="GetTotalNumber"...

public int GetTotalNumber()
{
using (SqlConnection conn =
new SqlConnection(ConnectionString))
{
using (SqlCommand cmd =
conn.CreateCommand())
{
cmd.CommandText = "select count(*) from ...;
conn.Open();
return = (int)cmd.ExecuteScalar();
}
}
}

GridView Examples for ASP.NET 2.0: Paging and Sorting the GridView's Data
http://msdn2.microsoft.com/en-us/library/aa479347.aspx
May 17 '07 #7

"Jeff Beem" <Je******@discussions.microsoft.comwrote in message
news:09**********************************@microsof t.com...
Hi Alexey,

I realize the ObjectDataSource supports this. My question is how do I
create an object that has the dynamic fields? For example, let's say I
have
a "Document" object that has a "DocumentId" property. That much is
static,
it will always have that property. However, the user can select that they
want to also see "Author", "LastSavedDate", "WordCount", etc. out of a
list
of potentially thousands of fields. Now, the stored procedure we have
will
return a dataset that has those fields (field1=DocumentId, field2=Author,
field3=LastSavedDate, etc.) But I don't have an object that has those
fields/properties. I agree that the ObjectDataSource is a good solution
for
custom paging. What I don't understand is how to get it to work with a
set
of fields that I won't know until runtime.
Hmm, but there is an ObjectDataSource.SelectMethod property, right?
It used to set the name of the method that selects the data.

<asp:objectdatasource
id="ObjectDataSource1"
runat="server"
selectmethod="GetAllDocuments"

Now, in the GetAllDocuments() you can define which fields you need to get
back from the database.

public static ICollection GetAllDocuments()
throws SqlException
{
string sql = "SELECT DocumentId";

if (user_has_selected == "Author")
sql += ",Author";
if (user_has_selected == "LastSavedDate")
sql += ",LastSavedDate";
...
sql += " FROM Documents";

SqlDataSource sds =
new SqlDataSource(cts.get_ConnectionString(sql),

if you want to use a stored procedure, you have to pass the fields as a
parameter,

for example

string fields = ""

string sql = "";

if (user_has_selected == "Author")
sql += ",Author";
if (user_has_selected == "LastSavedDate")
sql += ",LastSavedDate";

and build a dynamic SQL

CREATE PROC .... (

@fields nvarchar(max)

)

AS

SET @cmd = 'SELECT DocumentId' +

@fields

+ ' FROM...'

EXEC sp_executesql @cmd

go
May 17 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stephen | last post by:
This is a real brain-teaser and i'd really appreciate it if someone can try and understand what im trying to do and give me a few pointers or ideas to help me work out my problem. Im basically...
0
by: aftab | last post by:
Hi As i am doing a search results page where we have to list lots of results using paging in ASP.NET. I have two different databases one from sqlserver and one from oracle. so i have to query the...
3
by: Clint | last post by:
Hi, I am trying to implement the custom paging in the datalist in this format: << Prev 1,2,3,4,5 Next >>. Does anyone knows how to do this. Thanks in advance. Clint
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
2
by: asad | last post by:
hello friends, how ru all I want to create a custom paging logic in ASP.NET with a next link for example if i have 100 pages record so i want to show 6 pages link on page one and next link ...
0
by: richard | last post by:
OK, Im finished pulling my hair out and now I need help. I have created a VB class file for my custom paging, in it I create a table with 2 rows, in the rows I have linkbuttons for first page,...
3
by: Logu Krishnan | last post by:
in short, the question is "How do i do custom paging in my asp.net grids" in SQL 2000. if i use default paging and if my db has ~200000 records, then i have to select all the 2 lac records then...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
2
by: Ilyas | last post by:
Hi all I need to implmenet paging across different tables. The tables all have a different name eg Data01, data02 data03 etc, however they are columns which are common to each table, but each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.