|
|
||||||
|
#1
|
|
|
|
|
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 |
|
|
|
#2
|
|
|
|
|
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 (wawang, 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. |
|
#3
|
|
|
|
|
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]"" <wawang> wrote in message news:6140 [..] |
|
#4
|
|
|
|
|
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 (wawang, 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. |
|
#5
|
|
|
|
|
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]"" <wawang> wrote in message news:5604 [..] |
|
#6
|
|
|
|
|
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 (wawang, 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. |
|
#7
|
|
|
|
|
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]"" <wawang> wrote in message news:5532 [..] |
|
#8
|
|
|
|
|
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 (wawang, 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. |
|
#9
|
|
|
|
|
All right, close it :)
Thanks ""Walter Wang [MSFT]"" <wawang> wrote in message news:6140 [..] |
|
|
| Similar Threads | |
| Vista Ultimate 64 BSOD 0x00000050 PAGED FAULT IN NON PAGED AREA Hello, I am having a problem that I have been running into for the past few months. While I am trying to play a game, I will occasionally have a BSOD that calls out... |
|
| Folder View Option - Read Items vs. Total Items I am wondering if it is possible to for folders (in the folder list) to display the total number of items rather than the total number of unread items? For example,... |
|
| Total number of records paged gridview Hi, I have a paged gridview (Apts_grd) tied to an Access DataSource (Apts_srcGrd). How do I get the total number of data records returned by the query? The following shows... |
|
| Double paged line numbering with single paged text I have a legal transcript formatted with double-spaced line numbering or 25 lines. However, I need to single space some of the information in the title page of the document.... |
|
| Iterate thru text nodes, finding total string-length, Then trim to only 240 char in total for output Hello, I have a problem I am trying to solve which I hope someone can help. I have the below xml data. I want to review the combined length and then make sure when I... |
|
|
All times are GMT. The time now is 09:47 AM. | Privacy Policy
|