Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Show Event In Calendar Control

Posted on 2009-07-06
5
Medium Priority
?
1,389 Views
Last Modified: 2013-12-17
I have a calendar on a page that I would like to shade/color each day that has an event stored in a database.  I have a calendar control and a sqldatasource control on the page.  I currently have a datagrid bound to the calendar control so that when a day is selected if there are any events for that day, they are listed in the datagrid.  I would like to have the particular days highilghted in some fashion on the calendar to show the user which days have appointments.  I have done research on the web and know I should be using the DayRender function on the calendar, but the examples I'm finding are using page data rather than a sqldatasource or other sql data connection.
My schedule:</p>
            <asp:Calendar ID="Calendar1" runat="server" BackColor="White" 
                BorderColor="#3366CC" BorderWidth="1px" CellPadding="1" 
                DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" 
                ForeColor="#003399" Height="200px" Width="220px">
                <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
                <WeekendDayStyle BackColor="#CCCCFF" />
                <TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
                <OtherMonthDayStyle ForeColor="#999999" />
                <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
                <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
                <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" 
                    Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
            </asp:Calendar>
            <br />
            Appointments scheduled for selected day:<br />
            <asp:GridView ID="GridView1" 
                runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
                <Columns>
                    <asp:BoundField DataField="DateScheduled" HeaderText="Date" 
                        SortExpression="Date" />
                    <asp:BoundField DataField="TimeInScheduled" HeaderText="Start Time" 
                        SortExpression="Start Time" />
                    <asp:BoundField DataField="TimeOutScheduled" HeaderText="End Time" 
                        SortExpression="End Time" />
                    <asp:BoundField DataField="Patient" HeaderText="Patient" 
                        SortExpression="Patient" />
                    <asp:BoundField DataField="Description" HeaderText="Description" 
                        SortExpression="Description" />
                    <asp:HyperLinkField HeaderText="Enter Visit Notes" Text="Click Here" NavigateUrl="~/NewEntry.aspx"/>
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                SelectCommand="SELECT Visits.DateScheduled, Visits.TimeInScheduled, Visits.TimeOutScheduled, Patients.FirstName + ' ' + Patients.MiddleName + ' ' + Patients.LastName as Patient, VisitTypes.Description FROM Agencies INNER JOIN Patients ON Agencies.ID = Patients.AgencyID INNER JOIN Visits ON Patients.ID = Visits.PatientID INNER JOIN VisitTypes ON Visits.VisitTypeID = VisitTypes.ID WHERE (Visits.DateScheduled = @Date)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="Calendar1" DefaultValue="" Name="Date" 
                        PropertyName="SelectedDate" />
                </SelectParameters>
            </asp:SqlDataSource>
 
Database = 
 
Table = Visits
Field = DateScheduled
Format = Date

Open in new window

0
Comment
Question by:GY1680
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 24786804
I created an event calendar.  First off, what's complicating your situation is using the grid.  the Calendar itself is a table, so its redundant.  Then instead of binding you should write code in the dayRender to handle this...The only other thing I could see you trying is an if/else statement to see if there is a Datagrid control inside of the DayRender event.  The Bind should occur on each DayRender and should occur first, so maybe you can detect the datagrid and if it has one, then color it...
0
 

Author Comment

by:GY1680
ID: 24786897
I am attempting to use the calendar itself only to display if an event exists for that day, to indicate if the user should even bother clicking to find out more.  The datagrid is used to display a much more detailed view of the information.

I'm hoping to do something logically like this:

On DayRender
If Calendar1.Date = Sqldatasource.date
cell.color = blue
return
0
 
LVL 21

Assisted Solution

by:silemone
silemone earned 400 total points
ID: 24786975
oh...i see, when clicked, then datagrid pops up and shows event...did you look over this article?


http://odetocode.com/Articles/223.aspx

This shows you how to achieve this.  It may mean restructuring code a little.  Problems from my experience is that you would definitely have to use dayRender to mark the days for more control.  then bind data to the datagrid as in example...the flow would be

Create calendar  -- > get Events from DB ---> mark day with events --> onSelection -->bind data to Datagrid and show populated Datagrid...

What is the flow of your program?
0
 
LVL 21

Expert Comment

by:silemone
ID: 24787011
-->  I am attempting to use the calendar itself only to display if an event exists for that day, to indicate if the user should even bother clicking to find out more.  The datagrid is used to display a much more detailed view of the information......


In order to mark the days, you must use DayRender and in code, mark days...as my flow above suggest, you can then use Calendar onSelectedDate Event to THEN populate the DataGrid dynamically with that days events...
0
 

Accepted Solution

by:
GY1680 earned 0 total points
ID: 24787267
Thank you for the advice.

I had looked at the article you referenced, but as I mentioned - it gives a "made up" data source rather than pointing toward a SQL server.

I used this article:

http://www.dbtutorials.com/advanced/calendar-sql-organizer-cs.aspx

This helped me arrive at my final working solution that uses the returned values from a separate SQLDatasource and shades the days listed appropriately.  This data source is completely independent from the one that I have aligned to the data grid that shows "more information" when a date is clicked.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question