使用Google Calendar API v3和Data Repeater更改Google日历活动的标题

时间:2016-05-31 15:23:15

标签: c# asp.net google-calendar-api

我可以使用API​​密钥从Google日历中成功提取事件。

这些事件在我的网页上显示如下:
5/31/2016 9:00:00 AM - 5/31/2016 12:00:00 PM
活动标题:员工会议
描述:每周员工会议

我想设置"事件标题"的颜色。红色通过代码隐藏文件。我试图在我的dt.Rows.Add中改变它但是没有成功。有没有办法让我在后面的代码中更改它,以便只有"事件标题:"受影响了吗?

aspx代码

<div>        
    <asp:Repeater runat="server" ID="rptCalEvents">
        <ItemTemplate>                
            <asp:Label runat="server" ID="lblItemTemplate" Visible="true"> <%# Eval("Summary") %> </asp:Label>    
        </ItemTemplate>
    </asp:Repeater>
    <br />
    <asp:Label runat="server" ID="lblTesting" ForeColor="#660000" Font-Bold="true" Font-Size="15px" Visible="false"></asp:Label>        
</div>

aspx.cs代码

protected void Page_Load(object sender, EventArgs e)
{                
    GetCalEvents();
}
private void GetCalEvents()
{        
   var service = new CalendarService(new BaseClientService.Initializer()
   {
      ApiKey = "MY API KEY",
      ApplicationName = "Events Calendar",
   });

   DataTable dt = new DataTable();
   dt.Columns.Add("Summary");

   EventsResource.ListRequest request = service.Events.List("Google Calendar");
   request.TimeMin = DateTime.Now;
   request.TimeMax = DateTime.Today.AddDays(1);
   request.SingleEvents = true;
   request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

   Events events = request.Execute();
   if (events.Items != null && events.Items.Count > 0)
   {
      foreach (var eventItem in events.Items)
      {
         string when = eventItem.Start.DateTime.ToString();

         if (String.IsNullOrEmpty(when))
         {
            when = eventItem.Start.Date;
         }

         dt.Rows.Add(string.Format(when + " - " + eventItem.End.DateTime + "<br /><strong>" + "Event Title:" + "&nbsp;" + eventItem.Summary + "</strong>" + "<br /><strong>Event:</strong><br />" + eventItem.Description + "<hr/>"));
      }

      rptCalEvents.DataSource = dt;
      rptCalEvents.DataBind();
   }
   else
   {
      lblTesting.Visible = true;
      lblTesting.Text = "<strong>" + "No Upcoming Events for Today!!!" + "</strong>";
   }
}

1 个答案:

答案 0 :(得分:1)

您可以简单地换入<font>代码:

dt.Rows.Add(string.Format(when + " - " + eventItem.End.DateTime + "<br /><font color=\"red\"><strong>" + "Event Title:" + "&nbsp;" + eventItem.Summary + "</strong></font>" + "<br /><strong>Event:</strong><br />" + eventItem.Description + "<hr/>"));