Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I have to bind an <asp:calendar> with data fetched from a database using a linq query.

Here is the linq code


C#
public List<AllCalander> SearchCalender(int month, int zip, string type, int cause)
{
        var xyz = (from m in DB.Calenders 
                   where(m.DateFrom.Value.Month==month || m.Zip==zip || m.ActivityType==type || m.CauseID==cause) 
                   group m by new { m.DateFrom } into grp
                   select new
                   {
                       caustitle = grp.Select(x => x.Caus.CauseTitle),
                       datfrm = grp.Key.DateFrom,
                       total = grp.Count()
                   })
          .ToList()
          .Select(m => new AllCalander
          {


              DateFrom =Convert.ToDateTime(m.datfrm),
              CauseTitle = string.Join(",", m.caustitle),
              Total = m.total
          });

My aspx.cs code is here
C#
List<AllCalander> calnder = calbll.SearchCalender(mnth,ZipString,type,causeString);

foreach (var myItem in calnder)
{
    string datetime = myItem.DateFrom.ToString();

    Literal myEventNameLiteral = new Literal();
    myEventNameLiteral.ID = i + myItem.CauseID.ToString();

    // string currentcalanderDate = e.Day.Date.Day.ToString() ;
    if (string.Equals(DateTime.Parse(datetime).ToString("MMM dd yyyy"), e.Day.Date.ToString("MMM dd yyyy")))
    {
        string a = myItem.CauseTitle;

        if (a != cause)
            cause = a;

        coun++;

        myEventNameLiteral.Mode = LiteralMode.PassThrough;
        myEventNameLiteral.Text = "<br /><span style='font-family:verdana; font-size:10px;'>" + myItem.CauseTitle + "(" + myItem.Total + ")"+ " ";
        e.Cell.Controls.Add(myEventNameLiteral);
    }

    i++;
}


but on output it only shows the last value from database(overwriting the previous one) instead of showing all the data.

Can somebody please tell me what's wrong? Thanks in advance
Posted

1 solution

group m by new { m.DateFrom, m.Caus.CauseTitle }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900