Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > total items in paged output

Reply
Thread Tools

total items in paged output

 
 
Trapulo
Guest
Posts: n/a
 
      08-31-2007
Hello,
I've a gridview binded to an objectdataSource. Custom paging is enabled and
my objectdataSource is using a SelectCountMethod to retrieve the number of
total retrieved rows when it's showing only 25 rows at time (the rows that
the SelectMethd returns).
All works fine, but I need to show a label as "Total items: xxxx" on the
page, where xxxx is the total rows the select can retrieve (the value the
gridview uses to calculate total available pages number). I cannot make
this, can someone help me?

thanks


 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      09-03-2007
Hi Trapulo,

When you enabled EnablePaging for the ObjectDataSource, its Selected Event
will be called twice, one for the SelectMethod, one for the
SelectCountMethod. The event parameter ObjectDataSourceStatusEventArgs has
a property named ReturnValue will be the return value from the
SelectMethod/SelectCountMethod. Since the SelectMethod will return an
enumerable list and SelectCountMethod returns int, you can check for the
data type and get the returned record count:


protected void ObjectDataSource1_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
if (e.ReturnValue is int)
{
lblCount.Text = ((int)e.ReturnValue).ToString();
}
}



Hope this helps.


By the way, if you're selecting from database, you may find following tip
useful to improve performance:


#Update: GridView Custom Paging with ObjectDataSource
http://www.unboxedsolutions.com/sean...01/21/843.aspx


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
 
Trapulo
Guest
Posts: n/a
 
      09-07-2007
Great!
I didn't know this behavor! This solve my problem!

I'm not sure the System.Web.HttpContext.Current.Items solution the url you
suggested shows is better than mine.
My class has a global variable:
Private _totalRows As Int32

and the "select" method make this:

_totalRows = [total rows count from db]

then, the "selectcount" method is only a row:

Return _totalRows



I think my pattern has same advantages and doesn't involve httpcontent
collection, is this right? And it's early binded

thanks for your email too: I was out of office last days and I didn't
remember to check the NG.





""Walter Wang [MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Trapulo,
>
> When you enabled EnablePaging for the ObjectDataSource, its Selected Event
> will be called twice, one for the SelectMethod, one for the
> SelectCountMethod. The event parameter ObjectDataSourceStatusEventArgs has
> a property named ReturnValue will be the return value from the
> SelectMethod/SelectCountMethod. Since the SelectMethod will return an
> enumerable list and SelectCountMethod returns int, you can check for the
> data type and get the returned record count:
>
>
> protected void ObjectDataSource1_Selected(object sender,
> ObjectDataSourceStatusEventArgs e)
> {
> if (e.ReturnValue is int)
> {
> lblCount.Text = ((int)e.ReturnValue).ToString();
> }
> }
>
>
>
> Hope this helps.
>
>
> By the way, if you're selecting from database, you may find following tip
> useful to improve performance:
>
>
> #Update: GridView Custom Paging with ObjectDataSource
> http://www.unboxedsolutions.com/sean...01/21/843.aspx
>
>
> Regards,
> Walter Wang ((E-Mail Removed), remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      09-10-2007
Hi Trapulo,

Thanks for the confirmation.

A DataObject class can use static functions as SelectMethod and
SelectCountMethod, in that case, I think using HttpContext.Current.Items is
better since it avoids using static variable (which is not good since a
static variable will last in the entire life cycle as Asp.net worker
process).

In summary, for non-static SelectMethod/SelectCountMethod, I think using
either HttpContext.Current.Items or a member variable should both work. I
think the performance difference here will be trivial. I would perfer the
HttpContext.Current.Items approach since it avoids using a member variable.
Normally I will keep the DataObject class free of member variables.
However, this is only a personal taste.


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Trapulo
Guest
Posts: n/a
 
      09-10-2007
Thank you.
So I have a doubt: the ObjectDataSource creates a new instance of DataObject
when it needs to make a Select, and than it disposes that instance when it
has completed data retrieval (or insert, or update, etc.), doesn't it? If
this is the real behavor, I think that the static variable doesn't require
more resources that HttContext because all two solutions requires memory and
resources that release after the page has been rendered (at least). This is
wrong if I have a wrong idea of ObjectDataSource related lifecycles.

In fact I define al DataObject methods as Shared, but Select and SelectCount
not, so they can share the static variable about last row count.



""Walter Wang [MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Trapulo,
>
> Thanks for the confirmation.
>
> A DataObject class can use static functions as SelectMethod and
> SelectCountMethod, in that case, I think using HttpContext.Current.Items
> is
> better since it avoids using static variable (which is not good since a
> static variable will last in the entire life cycle as Asp.net worker
> process).
>
> In summary, for non-static SelectMethod/SelectCountMethod, I think using
> either HttpContext.Current.Items or a member variable should both work. I
> think the performance difference here will be trivial. I would perfer the
> HttpContext.Current.Items approach since it avoids using a member
> variable.
> Normally I will keep the DataObject class free of member variables.
> However, this is only a personal taste.
>
>
> Regards,
> Walter Wang ((E-Mail Removed), remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      09-11-2007
Hi Trapulo,

A static variable in a class doesn't bind to an instance, it's shared by
all instances of the class. Actually, if it's public, you can even access
the static variable without creating an instance of the class. The static
variable will have the same life cycle as the AppDomain. For asp.net, this
means it will live as long as the worker process is alive. You can verify
this by writing/reading a static variable in a class from two WebForm or
two postbacks.


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Trapulo
Guest
Posts: n/a
 
      09-11-2007
I'm sorry, there was a mistake explaining my solution. In my post 7
september, I wrote "global variable" : I don't use a static variable
(private shared count as int32), but a class variable (private _count as
int32 at class level).
Then in your reply at 10 september, you wrote "static variable" and I didn't
notice that (I'm sorry, I'm a VB developer and I I'm used to read "shared"
not "static" so I was not so obvious what static means).
With "global" I didn't mean "static", but only a class-scope variable. So,
using a standard variable and not a shared (static) I think that things are
different.

thanks



""Walter Wang [MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Trapulo,
>
> A static variable in a class doesn't bind to an instance, it's shared by
> all instances of the class. Actually, if it's public, you can even access
> the static variable without creating an instance of the class. The static
> variable will have the same life cycle as the AppDomain. For asp.net, this
> means it will live as long as the worker process is alive. You can verify
> this by writing/reading a static variable in a class from two WebForm or
> two postbacks.
>
>
> Regards,
> Walter Wang ((E-Mail Removed), remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      09-12-2007
Hi Trapulo,

Thanks for your clarification. I'm also sorry for the inconsistent terms
when describing the static/shared variables.

So I assume this issue can be closed now? Let me know if you have anything
else unclear. Thanks.


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Trapulo
Guest
Posts: n/a
 
      09-12-2007
All right, close it

Thanks


""Walter Wang [MSFT]"" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hi Trapulo,
>
> Thanks for your clarification. I'm also sorry for the inconsistent terms
> when describing the static/shared variables.
>
> So I assume this issue can be closed now? Let me know if you have anything
> else unclear. Thanks.
>
>
> Regards,
> Walter Wang ((E-Mail Removed), remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BT Total Broadband vs BT Business Total John Y UK VOIP 2 02-02-2007 09:27 AM
Total number of records paged gridview msch-prv@bluewin.ch ASP .Net 2 08-23-2006 07:41 AM
"paged" CAM table hash Ben Low Cisco 2 10-05-2004 07:29 PM
Explorer navigation errors with non-paged or large paged DataGrid. Richard Pimentel ASP .Net Datagrid Control 0 12-31-2003 06:32 PM
data from oledbdatreader can't paged by datagrid Yangtsi River ASP .Net 1 07-04-2003 02:32 PM



Advertisments