The GridView has a property named EmptyDataText that allows you to specify the text to display when there are no records.
Hope this helps.
mariano p. szklanny | developer :: Patterns & Practices | Web Client Software Factory Team
--------------------------------------------------------------------------------
I usually use asp:panel controls -- put the GridView in one, and a message with "Sorry, no records" in the other, and then hide/show depending on what's in the dataset.
--------------------------------------------------------------------------------
Thanks everyone for the help! It’s all working perfectly, although I do have one last issue I can’t figure out:
Super simple: how do you respond in a gridview when 0 results are returned? I just get a blank space—not even the headers show up. Is there a standard tag that lets me simply post “Sorry, no records were found!” or something?
MS
I agree … remember too you can easily set priority (e.g. NotRemovable, for hi-pri items) and also set dependencies, so it’s easy to build a “tree” of cache-related items.
-Brian
Mike,
They are right. It would be easier to invalidate the cache using Cache.
Also thinking about it some more, Cache is better about handling large amounts of data. Holding large amounts of data in Application state can fill up server memory which can cause paging. Cache manages the memory issue by flushing items that are close to expiration when memory becomes scarce.
Cache it should be.
Take a look at How To : Add Items to the Cache http://windowssdk.msdn.microsoft.com/en-gb/library/18c1wd61.aspx.
-Ian Bennett
Ok, instead of using the Cache object, I would use Application state. Something like:
DataSet playerData = null;
if (Application["Players"] == null)
{
// FILL playerData WITH DATA...
Application["Players"] = playerData;
}
else
{
playerData = (DataSet)Application["Players"];
}
// NOW DO SOMETHING WITH playerData
Hope this helps.
-Ian Bennett
Across all pages… let’s suppose it’s a list of active football players and a ton of people are hitting that page…. And the list only changes every day, but the query to get that list is really expensive for whatever reason. That’s what I’m getting at here.
MS
What’s the desired scope the cache, meaning do you want it cached for each user, for all users, etc.? Do you want to share the cache across pages?
-Ian Bennett
Hey guys,
I’m trying to cache an array of values—not too many, maybe 100 strings in one array. But let’s assume the query to the database takes 30 seconds and the data won’t change more than once/day. What’s the best way to do this? I’m looking into online examples but they are all way too advanced (caching data sources, using sql dependencies, etc.)
All I want to do is build this array during Page_Load and store it for one day (60*60*24 seconds):
protected void Page_Load(object sender, EventArgs e)
{
if (not_cached)
// load the connection to the database, run the query (which returns a vector so an array can store it)
else
// use cache
// store results in a string array
whatever[]
}
MS
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment