Cache Using ObjectDataSource

by rbellantoni 8/26/2010 7:02:00 AM

I needed to bind a large dataset to a gridview, it also contained numerous calculations that slowed down the database call, so I wanted to implement caching for the gridview I was using. 

So I used the default Caching on the ObjectDataSource. Which works great and well except for when you want to programatically refresh the data (say a new filter to be added). Turns out you can actually do it.

 

First make sure that in Page Load you set the CacheKeyDependency if it isn't set (you can also manually set it on the aspx page as a property of the ObjectDataSource):

        if (!IsPostBack)
        {
            //Create CacheKeyDependency if it doesn'tnot exists
            if (Cache[ObjectDataSource1.CacheKeyDependency] == null)
            {
                Cache[ObjectDataSource1.CacheKeyDependency] = new object();
            }
        }

In your code whenever you want the Select() of your ObjectDataSource to fire or just rebind from the database make this call:

Cache[ObjectDataSource1.CacheKeyDependency] = new object(); 

This allows you to programatically renew/refresh your datasource at will while still retaining the Cache abilities for paging/sorting/grouping etc.

Tags:

.NET | .NET WCF | BlogEngine.NET | SQL SERVER

ListView vs Gridview

by rbellantoni 4/7/2010 8:43:00 AM

Some people may be wondering what is the difference is between a ListView and a GridView. In my opinion, the ListView is a much better tool in regards to displaying and manipulating data. With the ListView you use templates to design the different views. The first template is the with this template you can dictate where you want your datarows to show up and how you want your data laid out here is an example:

<asp:ListView ID="lvProducerPools" runat="server" onitemdatabound="lvProducerPools_ItemDataBound" onitemcommand="lvProducerPools_ItemCommand" DataKeyNames="PoolID,Locked_flag">
<LayoutTemplate>
<div style="float:left;width: 1000px;overflow-x:auto;overflow-y:hidden;padding-top:5px; padding-bottom:15px;">
<table cellpadding="0" cellspacing="0" style="table-layout:fixed;height:18px;font-size:10pt;">
<tr style="height:18px;" id="itemPlaceholder" runat="server" />
</table>
</div>
</LayoutTemplate>
<ItemTemplate>
<td id="poolLInk" style="width:175px;height:18px;background-color:#cdcdcd;border-right:1px gray groove; padding: 2px;" runat="server">
<asp:LinkButton ID="lnkLoadPool" runat="server"> <%# Eval("PoolName")%></asp:LinkButton>
<asp:Image ToolTip="Deals in this allocation have been locked" ID="imgLock" runat="server" Visible='<%# Eval("Locked_flag")%>' ImageUrl="~/images/lock.gif" />
<asp:Label BorderColor="#8c9bad" BackColor="White" Font-Bold="true" BorderStyle="Double" BorderWidth="2px" ForeColor="Black" Font-Size="10px" ID="lblImbalance" runat="server" Text='<%# Eval("TLBalance")%>' >
</td>
</ItemTemplate>
<EmptyDataTemplate>
<table>
<tr>
<td id="poolLInk" style="background-color:#cdcdcd;border-right:1px gray groove; padding: 4px;" runat="server">
<b>NO PRODUCTION POINTS !!!
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>

The ID for "itemPlaceHolder" is not by accident, this is the identifier row where your itemtemplate rows will be bound. The advantage to this is that you have FULL control of how the html is rendered from your datasource. Whereas in a gridview your stuck with the table column design of the layout. Additionally you can use the datapager control inside of the template to enable paging, which does not work with the Gridview Control.

 

Tags:

.NET | ASP.NET AJAX | BlogEngine.NET | VB.NET

Ajax Loading Gif Generator

by rBellantoni 7/20/2009 8:18:00 AM

This website has one of the best ajax loading gif generators i've used and is completely free and customizable!

 http://www.ajaxload.info/

Tags:

.NET | BlogEngine.NET | VB.NET

Welcome to BlogEngine.NET 1.3

by Admin 12/21/2007 6:00:00 PM

If you see this post it means that BlogEngine.NET 1.3 is running and the hard part of creating your own blog is done. There is only one thing you need to do from this point on to take full advantage of the blog and that is to set up the first author profile.

Write Permissions

To be able to log in to the blog and writing posts, you need to enable write permissions on the App_Data folder. If you’re blog is hosted at a hosting provider, you can either log into your account’s admin page or call the support. You need write permissions on the App_Data folder because all posts and comments are saved as XML files and placed in the App_Data folder.

Username and password

When you've got write permissions to the App_Data folder, you need to change the username and password. Find the sign-in link located either at the bottom or top of the page depending on your current theme and click it. Now enter "admin" in both the username and password fields and click the button. You will now see an admin menu appear. It has a link to the "Users" admin page. From there you can change the username and password.

On the web

You can find BlogEngine.NET on the official website. Here you'll find tutorials, documentation, tips and tricks and much more. The ongoing development of BlogEngine.NET can be followed at CodePlex where the daily builds will be published for anyone to download.

Good luck and happy writing.

The BlogEngine.NET team

Tags: ,

BlogEngine.NET

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  July 2017  >>
MoTuWeThFrSaSu
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

View posts in large calendar

Recent comments

Tags

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

Sign in