asp:calendar将最后一个值绑定到数据库中

时间:2014-10-09 06:23:37

标签: asp.net linq linq-to-sql

我必须使用linq查询将<asp:calendar>绑定到从数据库获取的数据。

这是linq代码

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
          });

我的aspx.cs代码在这里

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 + ")"+ "&nbsp;";
        e.Cell.Controls.Add(myEventNameLiteral);
    }

    i++;
}

但是在输出时它只显示数据库中的最后一个值,而不是显示所有数据。

有人可以告诉我有什么问题吗? 提前致谢

1 个答案:

答案 0 :(得分:0)

将新的{m.DateFrom,m.Caus.CauseTitle}分组为grp