Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2009, 01:55 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default Maybe there is a better way??

Hello everyone,

Okay so here is what i am looking into now:

PROFILE.ASPX // the profile page of my social network site

Code:
 
protectedvoid Page_Load()
{

string conString = WebConfigurationManager.ConnectionStrings["myconnection"].ConnectionString;     // okay here
DataContext db = newDataContext(conString); // seems simple enough...
var tMessages = db.GetTable<Messages>();  // getting into new territory but i still get it.
tMessages.Where(m => m.Read == 0);  // This is kinda neat but i want the number of items in the list who have the Read property set to 0 (for false) so i can make my link button say "you have {0} messages!"
 
// and i was taking a shot in the dark thinking i'd be using something similar to this, in the sense of using the Sum method.

tMessages.Sum(m => m.Read == 0); 
}
 
now i was thinking of posting this list of unread messages to the next page:

VIEWMESSAGES.ASPX

Code:
 
protectedvoid Page_Load()
{

if (Page.PreviousPage != null)
{
// I was thinking of making a property on the previouspage i could grab the value from via this page and this property holds the list of messages (preferably just the new ones like so:
 
// PreviousPage.Property
 
// if that is something a professional developer wouldnt agree with, then perhaps it would be better to repeat the process of getting the unread messages list and databind it to a gridview

}
}
 
now this line here:

Code:
 
tMessages.Where(m => m.Read == 0);
my understanding of it is "in the Messages table where all Read messages are 0 (false)
im not sure what the "greater than equals to is for" ( => )...

anyways thanks for reading my multipart question. :)
 
Old March 9th, 2009, 08:34 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You will want to do something like this to get the count:

csharp Code:
var UnreadMessages =
      from m in db.Messages Where m.Read == 0
      Select m.UniqueID.Count();
 
Response.Write(UnreadMessages)

For info on Lambda expressions ( =>) go here:
http://www.developer.com/net/csharp/article.php/3598381

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old March 9th, 2009, 11:43 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

awesome thanks dparsons, im going to try it now
 
Old March 11th, 2009, 03:38 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

im thinking m.ID.Count() is supposed to be defined by me right?

because its saying that the method doesnt exist. just wanted to make sure im not missing a reference.

thanks doug :)
 
Old March 11th, 2009, 04:14 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I haven't followed / read the entire discussion, but maybe you're missing a using statement for System.Linq?

using System.Linq;

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 11th, 2009, 09:41 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

forgot to post back here and saying i got it.

but yes thats exactly what i missed... i put that statement in the wrong file.. :P *doh*









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.