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

Get the Selected Radiobutton from Radio Button List in Javascript

by ebarcza 8/20/2010 11:56:00 AM

Just pass in the clientid of the Radio button list control and this function will return the ID of the selected radio button so you can do what you want with it.

function GetRBLSelectionID(RadioButtonListID) {
    var RB1 = document.getElementById(RadioButtonListID);
    var radio = RB1.getElementsByTagName("input");
    var isChecked = false;
    var retVal = "";
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            retVal = radio[i].id;
            break;
        }
    }
    return retVal;
}

 

 

Tags: , ,

.NET | JavaScript

Export ListView to Excel

by jrose 8/20/2010 10:02:00 AM

All results that I came across when performing a search for export listview to excel were related to instances of Windows.Forms.ListView and not System.Web.UI.WebControls.ListView.

 

Attached are the two functions necessary to export instances of System.Web.UI.WebControls.ListView to Excel.

public override void VerifyRenderingInServerForm(Control control) { }

protected void btnExport_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.Buffer = true;
    Response.ContentType = "application/vnd.ms-excel";
    Response.Charset = "";
    this.EnableViewState = false;
    StringWriter stringWriter = new StringWriter();
    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
    listView.RenderControl(htmlTextWriter);
    Response.Write(stringWriter.ToString());
    Response.End();
}

Tags: , , ,

.NET | ASP.NET AJAX | Excel Programming

Listview DataRowView and ListViewDataItem

by rbellantoni 8/4/2010 5:01:00 AM

First you need to cast the listview item to a listviewdataitem, then you can cast it to a datarowview and pull out any information from the datasource like so

drv["Title"].ToString() 

 

CODE SNIPPET:

ListViewDataItem lvd = (ListViewDataItem)e.Item;

DataRowView drv = (DataRowView)lvd.DataItem;

Tags:

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

<<  November 2017  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

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