Brian
asked on
Display multiple entries in Calendar Control using DayRender Event
Hello EE,
I have the following code below that works fine displaying a Calendar's Cell with the Background Color and text. But the problem that I now face is that a user can have multiple entries for any given date. A user can Walk, Run, Swim and Golf for the date 8/11 and I need a way to display those different entries along with each entries color (color coded) for easier viewing.
My code as is follows below. I could really use alot of help on this post. I have had other EE members help me so far but this post was out of the range from my previous post.
I'm using ASP.NET 4.0 C#. I'm NOT using any third party controls. I have to use ASP.NET Calendar Control.
Thanks in advance!!
CODEBEHIND:
using System;
using System.Collections.Generic ;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ApplicationProcess_Secure_ PhysicalAc tivityLog : System.Web.UI.Page
{
string[,] palArr = null;
protected void Page_Load(object sender, EventArgs e)
{
hf_AppID.Value = Session["pi_id"].ToString( );
RetrieveCalendarNames();
if (!IsPostBack)
{
getPalDates();
}
}
//GET AVAILABLE DATE AND ITS CORRESPONDING NAME IN AN ARRAY
protected void getPalDates()
{
int pi_id = Convert.ToInt32(Session["p i_id"]);
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveDa tesForCale ndar";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = pi_id;
DataTable dtDates = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtDates);
palArr = new string[13, 32];
for (int iCnt = 0; iCnt <= dtDates.Rows.Count - 1; iCnt++)
{
Calendar1.SelectedDates.Ad d(Convert. ToDateTime (dtDates.R ows[0]["pa l_date"])) ;
DateTime dm = Convert.ToDateTime(dtDates .Rows[iCnt ]["pal_dat e"]);
palArr[dm.Month, dm.Day] = dtDates.Rows[iCnt]["palv_c ode"].ToSt ring() + "|" + dtDates.Rows[iCnt]["palv_i d"].ToStri ng();
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
// if (!day.IsOtherMonth)
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
string palName = palArr[day.Date.Month, day.Date.Day];
if (palName != null)
{
var p = palName.Split('|');
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 138, 215);
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 138, 140);
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 181, 138);
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 204, 138);
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 229, 138);
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 254, 138);
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 221, 255, 138);
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 146, 249, 134);
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 138, 238, 255);
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 136, 199, 252);
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 133, 146, 246);
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 195, 131, 242);
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
protected void MyCal_MonthChange(object sender, MonthChangedEventArgs e)
{
getPalDates();
}
protected void MyCal_SelectionChanged(obj ect sender, EventArgs e)
{
calendarExt.Show();
if (!IsPostBack)
{
RetrieveCalendarNames();
}
}
protected void RetrieveCalendarNames()
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_TestTest";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
try
{
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
ddl_Name.DataSource = rdr;
ddl_Name.DataValueField = "palv_id";
ddl_Name.DataTextField = "palv_names";
ddl_Name.DataBind();
rdr.Close();
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
protected void btn_SavePhysicalActivityLo g_Click(ob ject sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertPhys icalActivi tyLog";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = hf_AppID.Value;
cmd.Parameters.AddWithValu e("@palv_i d", SqlDbType.Int).Value = ddl_Name.SelectedItem.Valu e;
cmd.Parameters.AddWithValu e("@pal_da te", SqlDbType.DateTime).Value = Calendar1.SelectedDate.ToS hortDateSt ring();
//cmd.Parameters.AddWithVa lue("@pal_ id", SqlDbType.Int).Value = hf_pal_id.Value;
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
// ex.Message.ToString();
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("Physica lActivityL og.aspx");
conn.Close();
}
}
}
HTML MARKUP:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PhysicalActivity Log.aspx.c s" Inherits="ApplicationProce ss_Secure_ PhysicalAc tivityLog" %>
<%@ Register Assembly="AjaxControlToolk it" Namespace="AjaxControlTool kit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Wellness Choice Program - Physical Activity Log</title>
<link rel="stylesheet" href="../../css/main.css" type="text/css" />
</head>
<body>
<form id="form1" runat="server" defaultfocus="txtFirstName ">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div id="wrapper">
<div id="header">
<div id="logo">
<img src="../../images/logo.png " alt="The Wellness Choice Program Logo" />
</div>
<div id="nav">
</div>
</div>
<div id="content">
<div id="primary">
<h1>Physical Activity Log</h1>
<asp:Button runat="server" ID="targetBtn" style="display:none;"/>
<asp:Panel runat="server" style="display:none;" CssClass="modalPopup" ID="calendarPopup" Width="300px" Height="300px">
<!-- your form elements -->
<asp:Label ID="lblName" runat="server" CssClass="label" Text="Select Event to Perform: "></asp:Label><br />
<asp:DropDownList ID="ddl_Name" CssClass="ddl" runat="server"></asp:DropD ownList><b r /><br />
<br />
<asp:HiddenField ID="hf_AppID" runat="server" />
<asp:HiddenField ID="hf_pal_id" runat="server" />
<asp:Button ID="btn_SavePhysicalActivi tyLog" runat="server" Text="Save" onclick="btn_SavePhysicalA ctivityLog _Click" />
<asp:Button ID="CancelBtn" Text="Cancel" runat="server" /><br />
<asp:Label ID="lblSaveError" runat="server"></asp:Label >
</asp:Panel>
<asp:ModalPopupExtender ID="calendarExt"
runat="server"
TargetControlID="targetBtn "
PopupControlID="calendarPo pup"
CancelControlID="CancelBtn "
BackgroundCssClass="modalB ackground"
/>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#333333" Height="400px" Width="520px"
OnDayRender="MyCal_DayRend er" OnVisibleMonthChanged="MyC al_MonthCh ange" OnSelectionChanged="MyCal_ SelectionC hanged" DayNameFormat="Shortest"
ShowGridLines="True">
<DayHeaderStyle Font-Bold="True" BackColor="#027ABB" ForeColor="White"
Height="30px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#73BE1E"
Font-Bold="True" Font-Size="9pt" ForeColor="White" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="#333333" />
</asp:Calendar>
<br />
</div>
<div id="secondary">
<h1></h1>
<ul>
<li><asp:HyperLink ID="hl_HealthRiskAssess" runat="server" NavigateUrl="~/Application Process/Se cure/Healt hRiskAsses s.aspx">He alth Risk Assessment</asp:HyperLink> </li>
<li><asp:HyperLink ID="hl_AnnualPhysical" runat="server" NavigateUrl="~/Application Process/Se cure/Annua lPhysical. aspx">Annu al Physical</asp:HyperLink></ li>
<li><asp:HyperLink ID="hl_PreventiveScreening s" runat="server" NavigateUrl="~/Application Process/Se cure/Preve ntiveScree nings.aspx ">Preventi ve Screenings</asp:HyperLink> </li>
<li><asp:HyperLink ID="hl_GeneralHealthOne" runat="server" NavigateUrl="~/Application Process/Se cure/Gener alHealthAw arnessProg ramOne.asp x">General Health Awareness Program 1</asp:HyperLink></li>
<li><asp:HyperLink ID="hl_GeneralHealthTwo" runat="server" NavigateUrl="~/Application Process/Se cure/Gener alHealthAw arnessProg ramTwo.asp x">General Health Awareness Program 2</asp:HyperLink></li>
<li><asp:HyperLink ID="hl_GeneralHealthThree" runat="server" NavigateUrl="~/Application Process/Se cure/Gener alHealthAw arnessProg ramThree.a spx">Gener al Health Awareness Program 3</asp:HyperLink></li>
<li>Physical Activity Log</li>
</ul>
</div>
</div>
<div id="footer">
</div>
</div>
</form>
</body>
</html>
I have the following code below that works fine displaying a Calendar's Cell with the Background Color and text. But the problem that I now face is that a user can have multiple entries for any given date. A user can Walk, Run, Swim and Golf for the date 8/11 and I need a way to display those different entries along with each entries color (color coded) for easier viewing.
My code as is follows below. I could really use alot of help on this post. I have had other EE members help me so far but this post was out of the range from my previous post.
I'm using ASP.NET 4.0 C#. I'm NOT using any third party controls. I have to use ASP.NET Calendar Control.
Thanks in advance!!
CODEBEHIND:
using System;
using System.Collections.Generic
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ApplicationProcess_Secure_
{
string[,] palArr = null;
protected void Page_Load(object sender, EventArgs e)
{
hf_AppID.Value = Session["pi_id"].ToString(
RetrieveCalendarNames();
if (!IsPostBack)
{
getPalDates();
}
}
//GET AVAILABLE DATE AND ITS CORRESPONDING NAME IN AN ARRAY
protected void getPalDates()
{
int pi_id = Convert.ToInt32(Session["p
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveDa
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
cmd.Parameters.AddWithValu
DataTable dtDates = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtDates);
palArr = new string[13, 32];
for (int iCnt = 0; iCnt <= dtDates.Rows.Count - 1; iCnt++)
{
Calendar1.SelectedDates.Ad
DateTime dm = Convert.ToDateTime(dtDates
palArr[dm.Month, dm.Day] = dtDates.Rows[iCnt]["palv_c
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
// if (!day.IsOtherMonth)
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
string palName = palArr[day.Date.Month, day.Date.Day];
if (palName != null)
{
var p = palName.Split('|');
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
protected void MyCal_MonthChange(object sender, MonthChangedEventArgs e)
{
getPalDates();
}
protected void MyCal_SelectionChanged(obj
{
calendarExt.Show();
if (!IsPostBack)
{
RetrieveCalendarNames();
}
}
protected void RetrieveCalendarNames()
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_TestTest";
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
try
{
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
ddl_Name.DataSource = rdr;
ddl_Name.DataValueField = "palv_id";
ddl_Name.DataTextField = "palv_names";
ddl_Name.DataBind();
rdr.Close();
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
protected void btn_SavePhysicalActivityLo
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertPhys
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
//cmd.Parameters.AddWithVa
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
// ex.Message.ToString();
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("Physica
conn.Close();
}
}
}
HTML MARKUP:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PhysicalActivity
<%@ Register Assembly="AjaxControlToolk
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Wellness Choice Program - Physical Activity Log</title>
<link rel="stylesheet" href="../../css/main.css" type="text/css" />
</head>
<body>
<form id="form1" runat="server" defaultfocus="txtFirstName
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div id="wrapper">
<div id="header">
<div id="logo">
<img src="../../images/logo.png
</div>
<div id="nav">
</div>
</div>
<div id="content">
<div id="primary">
<h1>Physical Activity Log</h1>
<asp:Button runat="server" ID="targetBtn" style="display:none;"/>
<asp:Panel runat="server" style="display:none;" CssClass="modalPopup" ID="calendarPopup" Width="300px" Height="300px">
<!-- your form elements -->
<asp:Label ID="lblName" runat="server" CssClass="label" Text="Select Event to Perform: "></asp:Label><br />
<asp:DropDownList ID="ddl_Name" CssClass="ddl" runat="server"></asp:DropD
<br />
<asp:HiddenField ID="hf_AppID" runat="server" />
<asp:HiddenField ID="hf_pal_id" runat="server" />
<asp:Button ID="btn_SavePhysicalActivi
<asp:Button ID="CancelBtn" Text="Cancel" runat="server" /><br />
<asp:Label ID="lblSaveError" runat="server"></asp:Label
</asp:Panel>
<asp:ModalPopupExtender ID="calendarExt"
runat="server"
TargetControlID="targetBtn
PopupControlID="calendarPo
CancelControlID="CancelBtn
BackgroundCssClass="modalB
/>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#333333" Height="400px" Width="520px"
OnDayRender="MyCal_DayRend
ShowGridLines="True">
<DayHeaderStyle Font-Bold="True" BackColor="#027ABB" ForeColor="White"
Height="30px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#73BE1E"
Font-Bold="True" Font-Size="9pt" ForeColor="White" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="#333333" />
</asp:Calendar>
<br />
</div>
<div id="secondary">
<h1></h1>
<ul>
<li><asp:HyperLink ID="hl_HealthRiskAssess" runat="server" NavigateUrl="~/Application
<li><asp:HyperLink ID="hl_AnnualPhysical" runat="server" NavigateUrl="~/Application
<li><asp:HyperLink ID="hl_PreventiveScreening
<li><asp:HyperLink ID="hl_GeneralHealthOne" runat="server" NavigateUrl="~/Application
<li><asp:HyperLink ID="hl_GeneralHealthTwo" runat="server" NavigateUrl="~/Application
<li><asp:HyperLink ID="hl_GeneralHealthThree"
<li>Physical Activity Log</li>
</ul>
</div>
</div>
<div id="footer">
</div>
</div>
</form>
</body>
</html>
ASKER
Hello libby9284,
The adding multiple labels to a cell sounds like exactly what i need for this. How can I implemenet what you have above with the code below for the DayRender Event?
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
// if (!day.IsOtherMonth)
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
string palName = palArr[day.Date.Month, day.Date.Day];
if (palName != null)
{
var p = palName.Split('|');
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 138, 215);
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 138, 140);
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 181, 138);
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 204, 138);
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 229, 138);
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 254, 138);
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 221, 255, 138);
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 146, 249, 134);
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 138, 238, 255);
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 136, 199, 252);
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 133, 146, 246);
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 195, 131, 242);
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
The adding multiple labels to a cell sounds like exactly what i need for this. How can I implemenet what you have above with the code below for the DayRender Event?
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
// if (!day.IsOtherMonth)
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
string palName = palArr[day.Date.Month, day.Date.Day];
if (palName != null)
{
var p = palName.Split('|');
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
you may have to change the way you're storing the data in your app from the DB in the first place. It looks like the way you have it above that you'll only see the last event for the date render.
Instead of
in getPalDates(), use a delimiter and concatenate. I changed your code below to use a comma (if commas are expected for event data, use some other unexpected character).
palArr[dm.Month, dm.Day] += dtDates.Rows[iCnt]["palv_c ode"].ToSt ring() + "|" + dtDates.Rows[iCnt]["palv_i d"].ToStri ng() + ",";
then, in your day render event, change your function as follows:
if this doesn't help, please post sample data so I can better understand what's happening.
Instead of
palArr[dm.Month, dm.Day] = dtDates.Rows[iCnt]["palv_code"].ToString() + "|" + dtDates.Rows[iCnt]["palv_id"].ToString();
in getPalDates(), use a delimiter and concatenate. I changed your code below to use a comma (if commas are expected for event data, use some other unexpected character).
palArr[dm.Month, dm.Day] += dtDates.Rows[iCnt]["palv_c
then, in your day render event, change your function as follows:
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
// if (!day.IsOtherMonth)
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
//string palName = palArr[day.Date.Month, day.Date.Day];
string[] palEvents = palArr[day.Date.Month, day.Date.Day].Split(',');
for (int i = 0; i<palEvents.length; i++)
{
palName=palEvents[i];
if (palName != null)
{
var p = palName.Split('|');
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 215);
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 140);
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 181, 138);
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 204, 138);
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 229, 138);
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 254, 138);
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 221, 255, 138);
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 146, 249, 134);
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 138, 238, 255);
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 136, 199, 252);
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 133, 146, 246);
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 195, 131, 242);
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
}
if this doesn't help, please post sample data so I can better understand what's happening.
ASKER
Hi libby9284,
First of all I would like to thank you for your continued support for helping me out. I have never used the Calendar Class before with all it's Events, methods, etc... and I feel dumb because of it, so thank you again for helping me out....
As for the code you posted above, I did make the chagnes you suggested to test out and see what happens but please see the error messages i'm getting with red lines below.
LINE OF CODE:
for (int i = 0; i < palEvents.length; i++)
RED LINE MESSAGE:
'System.Array' does not contain a definition for 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)
LINE OF CODE:
palName = palEvents
RED LINE MESSAGE:
The name 'palName' does not exist in the current context.
LINE OF CODE:
if (palName != null)
RED LINE MESSAGE:
The name 'palName' does not exist in the current context.
LINE OF CODE:
var p = palName.Split('|');
RED LINE MESSAGE:
The name 'palName' does not exist in the current context.
>> if this doesn't help, please post sample data so I can better understand what's happening.
I can give you a sample of the data to gets added to the DB for the Calendar Control.
You can see below that pi_id -> 1277 has 4 entries for 8/20/2011 and in the event that a pi_id has more than one entry for a particular day then I need to display them.
pal_id pi_id palv_id pal_date
4000 1277 4 8/20/2011
4001 1277 8 8/20/2011
4002 1277 9 8/20/2011
4003 1277 12 8/20/2011
4004 1277 2 8/26/2011
First of all I would like to thank you for your continued support for helping me out. I have never used the Calendar Class before with all it's Events, methods, etc... and I feel dumb because of it, so thank you again for helping me out....
As for the code you posted above, I did make the chagnes you suggested to test out and see what happens but please see the error messages i'm getting with red lines below.
LINE OF CODE:
for (int i = 0; i < palEvents.length; i++)
RED LINE MESSAGE:
'System.Array' does not contain a definition for 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)
LINE OF CODE:
palName = palEvents
RED LINE MESSAGE:
The name 'palName' does not exist in the current context.
LINE OF CODE:
if (palName != null)
RED LINE MESSAGE:
The name 'palName' does not exist in the current context.
LINE OF CODE:
var p = palName.Split('|');
RED LINE MESSAGE:
The name 'palName' does not exist in the current context.
>> if this doesn't help, please post sample data so I can better understand what's happening.
I can give you a sample of the data to gets added to the DB for the Calendar Control.
You can see below that pi_id -> 1277 has 4 entries for 8/20/2011 and in the event that a pi_id has more than one entry for a particular day then I need to display them.
pal_id pi_id palv_id pal_date
4000 1277 4 8/20/2011
4001 1277 8 8/20/2011
4002 1277 9 8/20/2011
4003 1277 12 8/20/2011
4004 1277 2 8/26/2011
Glad to help! No reason to feel dumb about it, I spent a long time playing with this class for a site for someone else so its nice to be able to help someone else with it.
Sorry for the two mistakes there, use palEvents.Count instead of palEvents.length. I'm always doing that in my code :-p. And, put
Thanks for sending the data too, it reinforces what I thought the problem was.
Sorry for the two mistakes there, use palEvents.Count instead of palEvents.length. I'm always doing that in my code :-p. And, put
string palName;
before the loop. Thanks for sending the data too, it reinforces what I thought the problem was.
ASKER
It just gets frustrating when you need to have something done and don't know where to begin, especially for a Class that I never used. So thank you again for your continued help, patience, and knowledge...
I'm going to supply the code to make sure I added your code above correctly. I now only have one RED LINE. please see below.
LINE OF CODE:
for (int i = 0; i < palEvents.Count; i++)
RED LINE MESSAGE:
'System.Array' does not contain a definition for 'count' and no extension method 'count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
// if (!day.IsOtherMonth)
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
//string palName = palArr[day.Date.Month, day.Date.Day];
string[] palEvents = palArr[day.Date.Month, day.Date.Day].Split(',');
string palName;
for (int i = 0; i < palEvents.Count; i++)
{
palName = palEvents
if (palName != null)
{
var p = palName.Split('|');
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 138, 215);
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 138, 140);
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 181, 138);
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 204, 138);
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 229, 138);
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 255, 254, 138);
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 221, 255, 138);
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 146, 249, 134);
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 138, 238, 255);
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 136, 199, 252);
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 133, 146, 246);
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromA rgb(120, 195, 131, 242);
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
I'm going to supply the code to make sure I added your code above correctly. I now only have one RED LINE. please see below.
LINE OF CODE:
for (int i = 0; i < palEvents.Count; i++)
RED LINE MESSAGE:
'System.Array' does not contain a definition for 'count' and no extension method 'count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
// if (!day.IsOtherMonth)
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
//string palName = palArr[day.Date.Month, day.Date.Day];
string[] palEvents = palArr[day.Date.Month, day.Date.Day].Split(',');
string palName;
for (int i = 0; i < palEvents.Count; i++)
{
palName = palEvents
if (palName != null)
{
var p = palName.Split('|');
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromA
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
use palEvents.Length, a typo caused the error the first time, count is for something else (sorry for the confusion)
ASKER
Ok, palEvents.Length worked.
When I run the page i get the following error message below
LINE OF CODE:
if (p[1].ToString() == "2")
ERROR MESSAGE:
Index was outside the bounds of the array.
When I run the page i get the following error message below
LINE OF CODE:
if (p[1].ToString() == "2")
ERROR MESSAGE:
Index was outside the bounds of the array.
change palName = palEvents to
palName = palEvents[i]
ASKER
That is what I had already. For some reason I cannot upload the code to you with the bracket witht he i in it. When I try add that symbol I get the following error messgae below from EE. That is why I had to strip it out of the above code.
All tags must have a closing tag.
All tags must have a closing tag.
ASKER
Below is the code that gives me the error message below.
LINE OF CODE:
if (p[1].ToString() == "2")
ERROR MESSAGE:
Index was outside the bounds of the array.
LINE OF CODE:
if (p[1].ToString() == "2")
ERROR MESSAGE:
Index was outside the bounds of the array.
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
// if (!day.IsOtherMonth)
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
//string palName = palArr[day.Date.Month, day.Date.Day];
string[] palEvents = palArr[day.Date.Month, day.Date.Day].Split(',');
string palName;
for (int i = 0; i < palEvents.Length; i++)
{
palName = palEvents[i];
if (palName != null)
{
var p = palName.Split('|');
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 215);
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 140);
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 181, 138);
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 204, 138);
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 229, 138);
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 254, 138);
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 221, 255, 138);
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 146, 249, 134);
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 138, 238, 255);
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 136, 199, 252);
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 133, 146, 246);
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 195, 131, 242);
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
ok. Perhaps the issue is empty entries from the split?
if so, there's 2 options:
- change the split on the ',' character so that empty entries are removed (requires adding / changing the following)
- changing the if statement to ((palName != null) && (p.Length > 1))
if so, there's 2 options:
- change the split on the ',' character so that empty entries are removed (requires adding / changing the following)
... the rest of your code before the for loop
char[] delim = {','};
for (int i = 0; i < palEvents.Length; i++)
{
palName = palEvents[i];
... the rest of your code as it already is
- changing the if statement to ((palName != null) && (p.Length > 1))
ASKER
Hi libby9284,
Please see the following code below and the error message that I receive when first loading the page. I'm not sure if I placed what you mentioned above in the correct spot.
Also, when I tried performing your second option the if statement to ((palName != null) && (p.Length > 1)) . I got a red line with the following message below on this same line.
Red Line message:
The name 'p' does not exist in this current context.
Line of Code:
if (p[1].ToString() == "2")
Error Message:
Index was outside the bounds of the array.
Please see the following code below and the error message that I receive when first loading the page. I'm not sure if I placed what you mentioned above in the correct spot.
Also, when I tried performing your second option the if statement to ((palName != null) && (p.Length > 1)) . I got a red line with the following message below on this same line.
Red Line message:
The name 'p' does not exist in this current context.
Line of Code:
if (p[1].ToString() == "2")
Error Message:
Index was outside the bounds of the array.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ApplicationProcess_Secure_PhysicalActivityLog : System.Web.UI.Page
{
string[,] palArr = null;
protected void Page_Load(object sender, EventArgs e)
{
hf_AppID.Value = Session["pi_id"].ToString();
RetrieveCalendarNames();
if (!IsPostBack)
{
getPalDates();
}
}
//GET AVAILABLE DATE AND ITS CORRESPONDING NAME IN AN ARRAY
protected void getPalDates()
{
int pi_id = Convert.ToInt32(Session["pi_id"]);
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["WellnessChoice"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveDatesForCalendar";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@pi_id", SqlDbType.Int).Value = pi_id;
DataTable dtDates = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtDates);
palArr = new string[13, 32];
for (int iCnt = 0; iCnt <= dtDates.Rows.Count - 1; iCnt++)
{
Calendar1.SelectedDates.Add(Convert.ToDateTime(dtDates.Rows[0]["pal_date"]));
DateTime dm = Convert.ToDateTime(dtDates.Rows[iCnt]["pal_date"]);
// palArr[dm.Month, dm.Day] = dtDates.Rows[iCnt]["palv_code"].ToString() + "|" + dtDates.Rows[iCnt]["palv_id"].ToString();
palArr[dm.Month, dm.Day] += dtDates.Rows[iCnt]["palv_code"].ToString() + "|" + dtDates.Rows[iCnt]["palv_id"].ToString() + ",";
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
// if (!day.IsOtherMonth)
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
//string palName = palArr[day.Date.Month, day.Date.Day];
string[] palEvents = palArr[day.Date.Month, day.Date.Day].Split(',');
string palName;
// the rest of your code before the for loop
char[] delim = { ',' };
for (int i = 0; i < palEvents.Length; i++)
{
palName = palEvents[i];
// the rest of your code as it already is
//for (int i = 0; i < palEvents.Length; i++)
{
palName = palEvents[i];
if (palName != null)
{
var p = palName.Split('|');
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 215);
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 140);
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 181, 138);
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 204, 138);
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 229, 138);
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 254, 138);
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 221, 255, 138);
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 146, 249, 134);
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 138, 238, 255);
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 136, 199, 252);
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 133, 146, 246);
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 195, 131, 242);
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
}
}
protected void MyCal_MonthChange(object sender, MonthChangedEventArgs e)
{
getPalDates();
}
protected void MyCal_SelectionChanged(object sender, EventArgs e)
{
calendarExt.Show();
if (!IsPostBack)
{
RetrieveCalendarNames();
}
}
protected void RetrieveCalendarNames()
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["WellnessChoice"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_TestTest";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
try
{
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
ddl_Name.DataSource = rdr;
ddl_Name.DataValueField = "palv_id";
ddl_Name.DataTextField = "palv_names";
ddl_Name.DataBind();
rdr.Close();
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
protected void btn_SavePhysicalActivityLog_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["WellnessChoice"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertPhysicalActivityLog";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@pi_id", SqlDbType.Int).Value = hf_AppID.Value;
cmd.Parameters.AddWithValue("@palv_id", SqlDbType.Int).Value = ddl_Name.SelectedItem.Value;
cmd.Parameters.AddWithValue("@pal_date", SqlDbType.DateTime).Value = Calendar1.SelectedDate.ToShortDateString();
//cmd.Parameters.AddWithValue("@pal_id", SqlDbType.Int).Value = hf_pal_id.Value;
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
// ex.Message.ToString();
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("PhysicalActivityLog.aspx");
conn.Close();
}
}
}
Try this change. The logic that you need is the following and appears in the modified code snippet below:
- for each day, split all the events for that day into separate entries
- for each entry, split the entry to get the data you want and make a new label, adding it to the cal. cell
At this point its not really calendar class logic, its array and string manipulation.
- for each day, split all the events for that day into separate entries
- for each entry, split the entry to get the data you want and make a new label, adding it to the cal. cell
At this point its not really calendar class logic, its array and string manipulation.
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
char[] delim1 = { ',' };
char[] delim2 = {'|'};
string[] palEvents;
string palName;
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
// split concatenated events into array of events
palEvents = palArr[day.Date.Month, day.Date.Day].Split(delim1, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < palEvents.Length; i++)
{
// enumerate through events for given date
palName = palEvents[i];
// if the current event isn't null AND current event is in the assumed format
if ((palName != null) && palName.Contains("|"))
{
// split event data into different parts
var p = palName.Split(delim2, StringSplitOptions.RemoveEmptyEntries);
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 215);
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 140);
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 181, 138);
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 204, 138);
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 229, 138);
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 254, 138);
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 221, 255, 138);
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 146, 249, 134);
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 138, 238, 255);
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 136, 199, 252);
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 133, 146, 246);
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 195, 131, 242);
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
}
}
ASKER
Ok, when I run the page with the following code below I run into the same error message.
LINE OF CODE WITH ERROR:
if (p[1].ToString() == "2")
ERROR MESSAGE:
Index was outside the bounds of the array.
LINE OF CODE WITH ERROR:
if (p[1].ToString() == "2")
ERROR MESSAGE:
Index was outside the bounds of the array.
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
char[] delim1 = { ',' };
char[] delim2 = { '|' };
string[] palEvents;
string palName;
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
// split concatenated events into array of events
palEvents = palArr[day.Date.Month, day.Date.Day].Split(delim1, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < palEvents.Length; i++)
{
// enumerate through events for given date
palName = palEvents[i];
// if the current event isn't null AND current event is in the assumed format
if ((palName != null) && palName.Contains("|"))
{
// split event data into different parts
var p = palName.Split(delim2, StringSplitOptions.RemoveEmptyEntries);
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 215);
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 140);
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 181, 138);
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 204, 138);
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 229, 138);
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 254, 138);
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 221, 255, 138);
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 146, 249, 134);
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 138, 238, 255);
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 136, 199, 252);
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 133, 146, 246);
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 195, 131, 242);
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
}
Ok, here's the problem. something must be going wrong either while concatenating the data or while splitting it. You're going to need to run your application in debug mode after placing breakpoints.
If I were you, I'd try placing breakpoints at MyCal_DayRender and getPalDates() and then stepping through the code to see:
1 - what happens when the concatenation takes place
2 - what happens when the split on ',' takes place
3 - what happens when the split on '|' takes place
Looking at all of those things will help determine why its not splitting palName as you expect it to.
If I were you, I'd try placing breakpoints at MyCal_DayRender and getPalDates() and then stepping through the code to see:
1 - what happens when the concatenation takes place
2 - what happens when the split on ',' takes place
3 - what happens when the split on '|' takes place
Looking at all of those things will help determine why its not splitting palName as you expect it to.
ASKER
ok, so I setup breakpoints at the following lines below along with the values that where retrieved.
MyCal_DayRender Event:
char[] delim1 = { ',' };
Name Value Type
delim1 null char[]
delim2 null char[]
palEvents null string[]
palName null string
char[] delim2 = { '|' };
Name Value Type
delim1 {char[1]} char[]
[0] 44',' char
delim2 null char[]
palEvents null string[]
palName null string
When I added a breakpoint to the line below and tried stepping through the code it just kept skipping this line without displaying anything.
palEvents = palArr[day.Date.Month, day.Date.Day].Split(delim1 , StringSplitOptions.RemoveE mptyEntrie s);
When I added a breakpoint to the line below and tried stepping through the code it just kept skipping this line without displaying anything.
if ((palName != null) && palName.Contains("|"))
MyCal_DayRender Event:
char[] delim1 = { ',' };
Name Value Type
delim1 null char[]
delim2 null char[]
palEvents null string[]
palName null string
char[] delim2 = { '|' };
Name Value Type
delim1 {char[1]} char[]
[0] 44',' char
delim2 null char[]
palEvents null string[]
palName null string
When I added a breakpoint to the line below and tried stepping through the code it just kept skipping this line without displaying anything.
palEvents = palArr[day.Date.Month, day.Date.Day].Split(delim1
When I added a breakpoint to the line below and tried stepping through the code it just kept skipping this line without displaying anything.
if ((palName != null) && palName.Contains("|"))
Ok.
My guess is that commas are not a valid delimiter, they must be used somewhere in the data? You should try a different character (maybe a semicolon; you'll have to change the concatenation line and delim1)
One problem I think is that you're not using the debugger to its fullest potential. Since the breakpoints I suggested didn't seem to reveal much, I'd suggest you place a breakpoint at the top of the function (right next to the open bracket) and then step through the whole function. This way, you can trace your code and see exactly what is going on. There's two ways to see the data during runtime - using a watch or using the quickwatch utility. Right clicking on a variable while debugging gives you both options, quickwatch is my personal preference.
Additionally, you're going to have to step through the function multiple times because I don't think you have an event for every day of the month.
If its just skipping the if statement block completely (after if (!day.IsOtherMonth...)) then there's no data for that day (this means that when you're debugging it would skip the rest of the function entirely).
Try what I suggested and look at the contents of palArr[day.Date.Month, day.Date.Day], palEvents (look @ several indices) and palName. Data from these fields should help indicate what's wrong, along with keeping an eye on what day is being rendered too to check for consistency.
My guess is that commas are not a valid delimiter, they must be used somewhere in the data? You should try a different character (maybe a semicolon; you'll have to change the concatenation line and delim1)
One problem I think is that you're not using the debugger to its fullest potential. Since the breakpoints I suggested didn't seem to reveal much, I'd suggest you place a breakpoint at the top of the function (right next to the open bracket) and then step through the whole function. This way, you can trace your code and see exactly what is going on. There's two ways to see the data during runtime - using a watch or using the quickwatch utility. Right clicking on a variable while debugging gives you both options, quickwatch is my personal preference.
Additionally, you're going to have to step through the function multiple times because I don't think you have an event for every day of the month.
If its just skipping the if statement block completely (after if (!day.IsOtherMonth...)) then there's no data for that day (this means that when you're debugging it would skip the rest of the function entirely).
Try what I suggested and look at the contents of palArr[day.Date.Month, day.Date.Day], palEvents (look @ several indices) and palName. Data from these fields should help indicate what's wrong, along with keeping an eye on what day is being rendered too to check for consistency.
ASKER
Hi libby9284,
Ok, I think I may have found what you are looking for even though to me it's another language from another planet :(
I'm attaching a .txt file to keep the formatting because I'm worried about the formatting breaking if I add it here.
>> One problem I think is that you're not using the debugger to its fullest potential
Correct, I have not used the debugger much and need to learn more about it and its featrues.
Also, I'm gonig to display my table structure below again with actuall data that I have in there now.
pal_id pl_id palv_id pal_date
4027 1293 2 8/12/2011
4028 1293 4 8/12/2011
4029 1293 6 8/12/2011
4030 1293 11 8/13/2011
4031 1293 9 8/13/2011
EE-Debug.txt
Ok, I think I may have found what you are looking for even though to me it's another language from another planet :(
I'm attaching a .txt file to keep the formatting because I'm worried about the formatting breaking if I add it here.
>> One problem I think is that you're not using the debugger to its fullest potential
Correct, I have not used the debugger much and need to learn more about it and its featrues.
Also, I'm gonig to display my table structure below again with actuall data that I have in there now.
pal_id pl_id palv_id pal_date
4027 1293 2 8/12/2011
4028 1293 4 8/12/2011
4029 1293 6 8/12/2011
4030 1293 11 8/13/2011
4031 1293 9 8/13/2011
EE-Debug.txt
ASKER
Hi libby9284,
I was just playing around with different characters for the following line below and interestingly enough if I loaded the page for the first time using char[] delim1 = { ',' }; then it displays one entry which is normal now, but if I change the character below then the entry changes to a newer entry but keeping the same BG color for the Cell.
Not sure if this helps but I'm trying different things and so far I found that. Hopefully that may help in figuring out this issue.
char[] delim1 = { '/' };
I was just playing around with different characters for the following line below and interestingly enough if I loaded the page for the first time using char[] delim1 = { ',' }; then it displays one entry which is normal now, but if I change the character below then the entry changes to a newer entry but keeping the same BG color for the Cell.
Not sure if this helps but I'm trying different things and so far I found that. Hopefully that may help in figuring out this issue.
char[] delim1 = { '/' };
I just tried your code out in my workspace (w/ the data you sent me) and can't find a problem with that function. Your event data is formatted like this, from what you sent me:
B/S|6
Z|9
The data was split correctly based on the '|' character and on the ',' character.
What I had suggested before would have yielded data like this (let's pretend that the data on 8/12 and the data on 8/13 are all for 8/12)
the part of your code going to the DB for data would have ended up storing this:
palArr[8,12] = "B/S|6,Z|9";
Then, after the split based on comma palEvents will have 2 items,
palEvents[0] = "B/S|6"
palEvents[1] = "Z|9"
Then, your original code will split each of those based on '|', creating array p twice
first version of array p
p[0] = "B/S"
p[1] = 6
second version of array p
p[0] = "Z"
p[1] = "9"
Am I misunderstanding the scheme for your data?
ASKER
Hi libby9284
I'm not sure what all that means, I just took a look at the way the Date is stored in the DB and i'm not sure if this matters or not but it's stored differently then what i mentioned above.
As you will see I need to display 3 different labels for 8/12 and 2 different labels for 8/13. please forgive me for the pal_date format. I also apologize that i do not understand what you are explaining with B/S|6 and Z|9 :(
pal_id pi_id palv_id pal_date
4027 1294 2 2011-08-12 00:00:00.000
4028 1294 4 2011-08-12 00:00:00.000
4029 1294 6 2011-08-12 00:00:00.000
4030 1294 11 2011-08-13 00:00:00.000
4031 1294 9 2011-08-13 00:00:00.000
I'm not sure what all that means, I just took a look at the way the Date is stored in the DB and i'm not sure if this matters or not but it's stored differently then what i mentioned above.
As you will see I need to display 3 different labels for 8/12 and 2 different labels for 8/13. please forgive me for the pal_date format. I also apologize that i do not understand what you are explaining with B/S|6 and Z|9 :(
pal_id pi_id palv_id pal_date
4027 1294 2 2011-08-12 00:00:00.000
4028 1294 4 2011-08-12 00:00:00.000
4029 1294 6 2011-08-12 00:00:00.000
4030 1294 11 2011-08-13 00:00:00.000
4031 1294 9 2011-08-13 00:00:00.000
ASKER
Also, when I run the code I DO NOT recieve any errors but I'm only able to see one entry for each of those dates (8/12 and 8/13) instead of seeing all entries for each of those two dates.
i'm not sure what i'm saying that is confusing, please let me know what you're not understanding and i'll be happy to explain further.
the letters are coming from this part of your code, in getPalDates():
palArr[dm.Month, dm.Day] += dtDates.Rows[iCnt]["palv_c ode"].ToSt ring() + "|" + dtDates.Rows[iCnt]["palv_i d"].ToStri ng() + ",";
They're coming from the DB under column palv_code. So, for 8/12, there's a DB entry that looks like this
pal_id pi_id palv_code palv_id pal_date
4029 1294 B/S 6 2011-08-12 00:00:00.000
when the following runs
"B/S|6,"
That being said, it looks like the issue may actually be with your stored procedure. You should double check the procedure and see what exactly it is retrieving (perhaps you should run it manually in a database client to verify).
the letters are coming from this part of your code, in getPalDates():
palArr[dm.Month, dm.Day] += dtDates.Rows[iCnt]["palv_c
They're coming from the DB under column palv_code. So, for 8/12, there's a DB entry that looks like this
pal_id pi_id palv_code palv_id pal_date
4029 1294 B/S 6 2011-08-12 00:00:00.000
when the following runs
palArr[dm.Month, dm.Day] += dtDates.Rows[iCnt]["palv_code"].ToString() + "|" + dtDates.Rows[iCnt]["palv_id"].ToString() + ",";
it should take the palv_code (B/S), the '|', the palv_id (6), and a ',' and turn them into one string like this:"B/S|6,"
That being said, it looks like the issue may actually be with your stored procedure. You should double check the procedure and see what exactly it is retrieving (perhaps you should run it manually in a database client to verify).
ASKER
Hi libby9284,
sorry, I understand now what you mean by the letters/characters such as B/S|6. Please see my stored procedure below. When I execute it on the Server I get the following results back, so it seems that my SP is fine, at least from what i can tell.
Also, is there a reason why you are trying to return B/S|6 instead of just B/S?
So for example this is what I need it to look like inside the CELL assuming the date is 8-12-2011.
W
B/K
B/S
sorry, I understand now what you mean by the letters/characters such as B/S|6. Please see my stored procedure below. When I execute it on the Server I get the following results back, so it seems that my SP is fine, at least from what i can tell.
Also, is there a reason why you are trying to return B/S|6 instead of just B/S?
So for example this is what I need it to look like inside the CELL assuming the date is 8-12-2011.
W
B/K
B/S
Results from SP execution:
pi_id palv_id pal_date palv_names palv_code
1294 2 2011-08-12 Walking W
1294 4 2011-08-12 Boxing/Karate B/K
1294 6 2011-08-12 Biking/Spinning B/S
1294 11 2011-08-13 Aerobics/Pilates A/P
1294 9 2011-08-13 Zumba Z
STORED PROCEDURE:
ALTER PROCEDURE [dbo].[WellnessChoice_RetrieveDatesForCalendar]
(
@pi_id int
)
AS
SELECT pal.pi_id, pal.palv_id, pal.pal_date, palv.palv_names, palv.palv_code
FROM WellnessChoice_PhysicalActivityLog AS pal
INNER JOIN WellnessChoice_PhysicalActivityLogValues AS palv
ON pal.palv_id = palv.palv_id
WHERE pi_id = @pi_id
There's only two other things I can think of.
First idea (maybe data is getting lost b/w calls since websites are stateless):
- in your function getPalDates, in the finally block, save palArr to the Session
- in MyCal_DayRender, set palArr from the session
Second idea:
something is going wrong while iterating through the data in getPalDates; set a breakpoint at the line starting with
First idea (maybe data is getting lost b/w calls since websites are stateless):
- in your function getPalDates, in the finally block, save palArr to the Session
- in MyCal_DayRender, set palArr from the session
// example for retrieving multildimensional array
myMultiDimArr = (string[,])Session["myMultiDimArrKey"]
Second idea:
something is going wrong while iterating through the data in getPalDates; set a breakpoint at the line starting with
palArr[dm.Month, dm.Day] +=
and debug, seeing what is stored
ASKER
I was not sure how to save palArr to the Session and or set palArr from the Session.
I did set a breakpoint and I'm attaching the data that was collected based on the breakpoint you mentioned above.
EECode.txt
I did set a breakpoint and I'm attaching the data that was collected based on the breakpoint you mentioned above.
EECode.txt
ASKER
Note: You may notice that i removed the character "/" from B/K, B/S, and A/P just in case you where wondering. I removed it in the DB to see if maybe that was causing it but I get the same results.
For trying the first idea:
its the same as how you're already using the session in the code. Session is a key based collection so, make a new key. For example, if I had a string array called myArray and I wanted to put it in the session object (saving the data in its current state) i could do this after I've finished putting my data into the array:
Then later on in another function, I can retrieve my array like this in order to use it again.
you're storing the right data in the array (according to the txt file you posted) but the data isn't going to just stay there across callbacks to the server, its a quirk of web development. If you're going to need something later in another function, save it to Session or Viewstate (Session is more efficient, ViewState is more secure but can slow things down greatly).
its the same as how you're already using the session in the code. Session is a key based collection so, make a new key. For example, if I had a string array called myArray and I wanted to put it in the session object (saving the data in its current state) i could do this after I've finished putting my data into the array:
Session["myArray_saved"] = myArray
Then later on in another function, I can retrieve my array like this in order to use it again.
string[] myArray = (string[])Session["myArray_saved"]
you're storing the right data in the array (according to the txt file you posted) but the data isn't going to just stay there across callbacks to the server, its a quirk of web development. If you're going to need something later in another function, save it to Session or Viewstate (Session is more efficient, ViewState is more secure but can slow things down greatly).
ASKER
Yeah, it's frustrating because like you said the .txt file is retrieving the correct data.
Which Event and where in the Event do I need to add the following code below to?
Session["myArray_saved"] = myArray
string[] myArray = (string[])Session["myArray _saved"]?
Which Event and where in the Event do I need to add the following code below to?
Session["myArray_saved"] = myArray
string[] myArray = (string[])Session["myArray
I wasn't giving you the explicit code in the last post, I was giving you an example to extrapolate from.
Before getPalDates() exits, you need to save your array.
Before using palArr in MyCal_DayRender, you need to retrieve your array.
You can find more examples of using Session to save your data between callbacks here, the link explains its purpose and how to use it
Before getPalDates() exits, you need to save your array.
Before using palArr in MyCal_DayRender, you need to retrieve your array.
You can find more examples of using Session to save your data between callbacks here, the link explains its purpose and how to use it
ASKER
Ok, I'm just very confused at this point. The last thing I want to do is create another post in regards to storing getPalDates to Session but I will so that we can hopefully find the calprit to this mystery. I have stored data to Sessions before but not to this extent.
its no different, its the same idea. the only difference is the cast when you retrieve it, the cast has to be the same type as palArr (a two dimensional array of type string).
ASKER
Hi libby9284,
I'm going to create another post with what you are asking since I'm not sure how to implement the array into session. Once I hear back from them I will notify you. Hopefully by doing this is resolves the problem. also, you said that you tested this out on your end it was fine, what did you do differently? Also, i don't need to have the palv_code next to the palv_id. I only need to display "W", "B/S", "Z" etc...
so if user has multiple entries for one date then it only needs to show the palv_code values.
I'm going to create another post with what you are asking since I'm not sure how to implement the array into session. Once I hear back from them I will notify you. Hopefully by doing this is resolves the problem. also, you said that you tested this out on your end it was fine, what did you do differently? Also, i don't need to have the palv_code next to the palv_id. I only need to display "W", "B/S", "Z" etc...
so if user has multiple entries for one date then it only needs to show the palv_code values.
ASKER
Hi libby9284,
Ok, I was able to get some help storing what you asked in Session. Please see the code below. Also, once I added the code and ran the page I did NOT notice anything differently than before. I'm still not understanding how you got your example to work on your end.
Ok, I was able to get some help storing what you asked in Session. Please see the code below. Also, once I added the code and ran the page I did NOT notice anything differently than before. I'm still not understanding how you got your example to work on your end.
ASKER
Sorry, fogot to upload code as you requested for storing the Array in Session.
//GET AVAILABLE DATE AND ITS CORRESPONDING NAME IN AN ARRAY
protected void getPalDates()
{
int pi_id = Convert.ToInt32(Session["pi_id"]);
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["WellnessChoice"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveDatesForCalendar";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@pi_id", SqlDbType.Int).Value = pi_id;
DataTable dtDates = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtDates);
palArr = new string[13, 32];
for (int iCnt = 0; iCnt <= dtDates.Rows.Count - 1; iCnt++)
{
Calendar1.SelectedDates.Add(Convert.ToDateTime(dtDates.Rows[0]["pal_date"]));
DateTime dm = Convert.ToDateTime(dtDates.Rows[iCnt]["pal_date"]);
palArr[dm.Month, dm.Day] = dtDates.Rows[iCnt]["palv_code"].ToString() + "|" + dtDates.Rows[iCnt]["palv_id"].ToString();
}
Session["myArray_saved"] = palArr;
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
//CUSTOMIZE UR CALENDAR RENDER EVENT NOW
protected void MyCal_DayRender(object sender, DayRenderEventArgs e)
{
char[] delim1 = { ',' };
char[] delim2 = { '|' };
string[] palEvents;
string palName;
palArr = (string[,])Session["myArray_saved"];
// remove if (!IsPostBack) if running into Render errors
if (!IsPostBack)
{
CalendarDay day = (CalendarDay)e.Day;
TableCell cell = (TableCell)e.Cell;
if (!day.IsOtherMonth && palArr[day.Date.Month, day.Date.Day] != null)
{
// split concatenated events into array of events
palEvents = palArr[day.Date.Month, day.Date.Day].Split(delim1, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < palEvents.Length; i++)
{
// enumerate through events for given date
palName = palEvents[i];
// if the current event isn't null AND current event is in the assumed format
if ((palName != null) && palName.Contains("|"))
{
// split event data into different parts
var p = palName.Split(delim2, StringSplitOptions.RemoveEmptyEntries);
if (p[1].ToString() == "2")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 215);
}
else if (p[1].ToString() == "3")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 138, 140);
}
else if (p[1].ToString() == "4")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 181, 138);
}
else if (p[1].ToString() == "5")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 204, 138);
}
else if (p[1].ToString() == "6")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 229, 138);
}
else if (p[1].ToString() == "7")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 255, 254, 138);
}
else if (p[1].ToString() == "8")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 221, 255, 138);
}
else if (p[1].ToString() == "9")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 146, 249, 134);
}
else if (p[1].ToString() == "10")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 138, 238, 255);
}
else if (p[1].ToString() == "11")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 136, 199, 252);
}
else if (p[1].ToString() == "12")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 133, 146, 246);
}
else if (p[1].ToString() == "13")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(120, 195, 131, 242);
}
Label lbl = new Label();
lbl.Text = "<br>" + p[0];
e.Cell.Controls.Add(lbl);
}
}
}
}
}
Change line 31 above to use The += operator instead of = ( I.e. palArr[dm.Month, dm.Day] += ...)
In your other posts you had +=, which would have concatenated entries.
What you have in this post will overwrite data. Each time you get an event for a given date it will overwrite the data stored in that index of the array. Changing the operator should fix it.
In your other posts you had +=, which would have concatenated entries.
What you have in this post will overwrite data. Each time you get an event for a given date it will overwrite the data stored in that index of the array. Changing the operator should fix it.
ASKER
ok, made the change below as you mentioned and this time it displayed a different single value to a date. Still does not dislpay all entries for a particular date :(
palArr[dm.Month, dm.Day] += dtDates.Rows[iCnt]["palv_c ode"].ToSt ring() + "|" + dtDates.Rows[iCnt]["palv_i d"].ToStri ng();
palArr[dm.Month, dm.Day] += dtDates.Rows[iCnt]["palv_c
ASKER
Hi libby9284,
This will give you an idea as to what I would like the multiple entries to look like when all differrent values to be dislayed for a given date if more than one entry per date exist.
If you read Part 2 and run the demo at the bottom then you will see what I mean.
http://www.4guysfromrolla.com/articles/041603-1.aspx
This will give you an idea as to what I would like the multiple entries to look like when all differrent values to be dislayed for a given date if more than one entry per date exist.
If you read Part 2 and run the demo at the bottom then you will see what I mean.
http://www.4guysfromrolla.com/articles/041603-1.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi libby9284,
Ok, I'm glad to let you know that your last post worked :) Thank you so VERY MUCH!!!! libby9284 for your time, patience, understanding, knowledge, and detication to help others. I wish that one day I can be as good as you!!!!
There are a couple minor issues that I found but I'm sure to you they are prob nothing. The problem that i noticed is that if I where to select another month by clicking on the "Next" and "Previous" links then the data does not get displayed for the other months. If i'm at the other month and trying going back to view what was first loaded then nothing displays either.
It only displays the values on Page_Load and after that they disappear.
Ok, I'm glad to let you know that your last post worked :) Thank you so VERY MUCH!!!! libby9284 for your time, patience, understanding, knowledge, and detication to help others. I wish that one day I can be as good as you!!!!
There are a couple minor issues that I found but I'm sure to you they are prob nothing. The problem that i noticed is that if I where to select another month by clicking on the "Next" and "Previous" links then the data does not get displayed for the other months. If i'm at the other month and trying going back to view what was first loaded then nothing displays either.
It only displays the values on Page_Load and after that they disappear.
I'm glad I could help :) . For the current issue, you should look at your dayrender function. You're using a check of !IsPostback before the bulk of the function's code - this means that that code will only run during the initial pageload.
Frequently its useful to only do certain things once when the page first loads (like, for efficiency, for changing the way the page displays for different user types, etc). But, for the calendar dayrender event, doing the bulk of the dayrender code only during the initial page load is kind of shooting yourself in the foot. Can you see why?
Frequently its useful to only do certain things once when the page first loads (like, for efficiency, for changing the way the page displays for different user types, etc). But, for the calendar dayrender event, doing the bulk of the dayrender code only during the initial page load is kind of shooting yourself in the foot. Can you see why?
ASKER
Yes, that makes sense and yes that worked very well now :) Thanks!!!
Now for the million dollar question :)
Now that you created me a miracle is there anyway to do exactly what we did but with 12 Calendar Controls instead of just one? So instead of showing just one control per page we can show 12 Calendar Controls one calendar for every month starting with this month?
If so, then I would like to work with you on it if you would be willing and I can create another post for that as well.
Now for the million dollar question :)
Now that you created me a miracle is there anyway to do exactly what we did but with 12 Calendar Controls instead of just one? So instead of showing just one control per page we can show 12 Calendar Controls one calendar for every month starting with this month?
If so, then I would like to work with you on it if you would be willing and I can create another post for that as well.
Yes, there should be, but I haven't done it before and the way I'm thinking it could be done may have a few latency issues. Could you give me a better idea of what your background is so I have a better idea of how to help you?
ASKER
What type of latency issues?
Do you mean the background as to what I would like to do, or my background?
Do you mean the background as to what I would like to do, or my background?
ASKER
I would like to display 12 calendars like the tutorial below but keep everything we did the same but to expand to the other controls.
http://weblogs.sqlteam.com/jhermiz/archive/2007/12/10/Cool-Tricks-With-The-ASP.net-Calendar.aspx
http://weblogs.sqlteam.com/jhermiz/archive/2007/12/10/Cool-Tricks-With-The-ASP.net-Calendar.aspx
possible source of latency with 12 calendar controls:
day render will have to run about 12 times as often as it currently does (1 set of about 31 days for each of 12 calendars, totaling about 372 round trip calls to the server each time the calendars on the page render)
But, looking at the link you sent me, it looks like its been done before without complaint. Which means this should be fairly straightforward. It should simply be a matter of wiring the additional calendars' dayrender event to the other calendar controls as well and modifying your getPalDates function to accept the month as a parameter. Otherwise, you should be able to extrapolate from the tutorial you already found.
and by background, i was trying to understand what you're background experience is so I could help you more efficiently
day render will have to run about 12 times as often as it currently does (1 set of about 31 days for each of 12 calendars, totaling about 372 round trip calls to the server each time the calendars on the page render)
But, looking at the link you sent me, it looks like its been done before without complaint. Which means this should be fairly straightforward. It should simply be a matter of wiring the additional calendars' dayrender event to the other calendar controls as well and modifying your getPalDates function to accept the month as a parameter. Otherwise, you should be able to extrapolate from the tutorial you already found.
and by background, i was trying to understand what you're background experience is so I could help you more efficiently
ASKER
Ok, if I would create another post would you be willing to help me?
My background is 1yr. using C#. 4yrs. with ASP.NET using mostly (CRUD) create, retrieve, update, and delete operations using ADO.NET.
My background is 1yr. using C#. 4yrs. with ASP.NET using mostly (CRUD) create, retrieve, update, and delete operations using ADO.NET.
Ok.
ASKER
Hi libby9284,
Thanks, please let me know once you recieve this so i can close this post. Once again thank you for ALL YOUR HELP...
https://www.experts-exchange.com/questions/27255568/Display-12-Calendar-Controls.html
Thanks, please let me know once you recieve this so i can close this post. Once again thank you for ALL YOUR HELP...
https://www.experts-exchange.com/questions/27255568/Display-12-Calendar-Controls.html
ok got it
ASKER
Thank you again VERY much libby for all your time, patience, and knowledge.
My solution to this on that site was to get all events for the month and loop through all of them for each dayrender event, checking if the date of the DB event item matched the dayrender date and then adding the labels to that event if it matched. A hash or dictionary probably would have been more efficient but it works well enough as it is for that site.
Below is an example, tbl is a DataTable object and t is a DateTime object. The code runs when the DayRender event fires
Open in new window