cache a datalist!

K

Kyong Kwak

Hey all my second post!

wanted to know if I can cache an entire control.. this is what I have..

Webform has header, nav, footer, and Usercontrol_1. Usercontrol_1 has a
datalist and paging items ( prev, current page, next ).

I wanted to output cache for each "page" of the datalist, but I can't
seem to get it to work ( any suggestions? ). It would only cache at the
usercontrol level. so I'd get the header, nav, foot, and Usercontrol_1
but not page two of Usercontrol_1.

I want to know how I can cache multiple instances of the Usercontrol_1
for each page.

In the meanwhile I tried caching the DataList object, but when I get it
from the cache, the DataListItems don't render! any thoughts?

thanks!

p.s. I put the DataList in the cache after the .DataBind() call.

kyong
 
K

Kyong Kwak

// Does this help? Looking at it, I noticed that the cachedObject state
is PreRendered. There isn't a way to change the state of the control
from what I know. I looked at the content and everything is there. All
the data is fine, I just don't know why it is not rendering out! THANKS!!!!

private void Page_Load(object sender, System.EventArgs e) {
if( !IsPostBack ) {
BindList();
}
else {
DataList cachedObject = ( DataList )Cache[ "cachedList" ];
if( cachedObject != null )
myDataList = cachedObject;
else
BindList();
}
}

private void BindList() {
// get bindable arraylist
myDataList.DataSource = arraylist;
myDataList.DataBind();
Cache[ "cachedList" ] = myDataList;
}

// Wired properly for ItemBind {
private void myDataList_ItemDataBound(
object sender, DataListItemEventArgs e) {

if( ( e.Item.ItemType == ListItemType.Item ) ||
( e.Item.ItemType == ListItemType.AlternatingItem ) ) {

DataList theDataList= ( DataList )sender;
ArrayList listIDs= ( ArrayList )theDataList.DataSource;
int _productID = ( int )listIDs[ e.Item.ItemIndex ];
ProdInfo info= new ProdInfo( _productID );
this.SetProductInfo( info, e.Item );
}
}
 
G

Guest

why are u not caching the arraylist ??
And just bind the arraylist..

Kyong Kwak said:
// Does this help? Looking at it, I noticed that the cachedObject state
is PreRendered. There isn't a way to change the state of the control
from what I know. I looked at the content and everything is there. All
the data is fine, I just don't know why it is not rendering out! THANKS!!!!

private void Page_Load(object sender, System.EventArgs e) {
if( !IsPostBack ) {
BindList();
}
else {
DataList cachedObject = ( DataList )Cache[ "cachedList" ];
if( cachedObject != null )
myDataList = cachedObject;
else
BindList();
}
}

private void BindList() {
// get bindable arraylist
myDataList.DataSource = arraylist;
myDataList.DataBind();
Cache[ "cachedList" ] = myDataList;
}

// Wired properly for ItemBind {
private void myDataList_ItemDataBound(
object sender, DataListItemEventArgs e) {

if( ( e.Item.ItemType == ListItemType.Item ) ||
( e.Item.ItemType == ListItemType.AlternatingItem ) ) {

DataList theDataList= ( DataList )sender;
ArrayList listIDs= ( ArrayList )theDataList.DataSource;
int _productID = ( int )listIDs[ e.Item.ItemIndex ];
ProdInfo info= new ProdInfo( _productID );
this.SetProductInfo( info, e.Item );
}
}

Pls post some code..

:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,330
Latest member
AlvaStingl

Latest Threads

Top