 |
BOOK: Beginning ASP.NET 1.1  | This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

October 6th, 2007, 01:06 PM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Custom Calendar Control
I'm trying to implement a custom version (VS 2003) of the ASP.Net Calendar control. I want to load the object with an ArrayList, that loads a Class with 2 properties- Date and TypeOfDate. (y'know, birthdays, anniversaries). I'm having trouble pulling the parts out of the class, but mostly assigning the DateItem to the Web.CalendarSelectedDates collection. It compiles ok, but errors when run. Most of the examples I've seen allow you to customize format with a given date range- assumes you know what it is. The Type would load selected dates in the collection, but then allow a switch to format based on type.
Any help would be appreciated. Cheers
|
|

October 6th, 2007, 05:32 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
hmm. I am not sure what you mean. Do you mean to say that you are trying to create a custom control that inherits from the Calendar control and, moreover, you are trying to customize how the calendar is rendered based off of the contents of an array??
In any event, if this is what you are trying to do, I do not see the need for a custom control. The Calendar exposes an event, DayRender, that fires when a day is rendered for a given month. (The event will fire at least 28 times)
Now the fun part. You say that you have an ArrayList that loads a class (a custom type I would assume) so, I assume, the ArrayList contains many instances of this type. The DayRender event signature looks like this:
protected void calendar_DayRender(object sender, DayRenderEventArgs e)
{
}
if you use the eventArgs you will see that you can do something like this:
DateTime dt = e.Day.Date;
So, if I have assumed correctly, you could potentially do something like this:
Code:
protected void calendar_DayRender(object sender, DayRenderEventArgs e)
{
foreach(<customtype> in <arraylist>)
{
if(<customtype>.Date == e.Day.Date)
{
//Do something with this cell
return;
}
}
}
hth.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
|
|

October 6th, 2007, 05:53 PM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I've already got the set up like you posted. I'm writing a custom control that inherits from the Calendar. The ArrayList can only take one argument, such as Date. I want my dates to have 2 properties, a date and a type of date, such as a birthday or holiday, so I created a class to do that. I populate the ArrayList with instances of the class. OnDayRender, I want each date in the List to be Selected, but also have a different color based on it's type. The DatesCollection used by the Calendar expects a date, not the class I'm using, so how do I just pass the Date portion from the ArrayList to the Calendar?
Hope that make it a little clearer. Thanks
|
|

October 6th, 2007, 05:57 PM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I should have read you post a little better- What you have may work. I knew I was pretty close on my solution since it compiled fine. I'll give it a try. Thanks again
|
|

October 16th, 2007, 07:47 PM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I sent a reply today, but it does not seem to have posted. ANy reason for this?
|
|

October 16th, 2007, 08:07 PM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'll try again. I will start with what I am trying to implement, what works, and what doesn't.
I am trying to implement a custom calendar composed of 1. a custom Calendar class that inherits from the Calendar Control, and 2. a Custom Year Class that inherits from #1. and displays the whole year. Also on the page with the Year Control is a DataGrid that displays the Data for a given selected day. It displays the date, the Category of day, the hours billed. I have the Edit/Update and Delete commands working, so that when I change a category, it re-renders the date's properties on the Year View, changes the date for that entry, or deletes that date depending on option chosen.
What I am having a great deal of trouble with selecting/deselecting dates on the Year View. I am able to add/delete them from the SelectedDates collection (and render it OK). But I am unable to make this change update the database table, or the DataGrid it's bound to. I have tried to use a multi-dimension ArrayList which adds an object (Class with Date and Category properties) to the ArrayList, and the SelectedDates Collection. Adding works, but I am unable to delete a Date from the ArrayList. I iterate (for...each) the objects in it, get the Index that matches the date, pass this to a temp variable, and then use this temp var to Remove at the index (Since you can't change the ArrayList while iterating). It doesn't throw an error, but also fails to remove the object. How do I get these custom classes to communicate information back to the page and vice versa. Can I raise an event in the Containing page from the Custom Control? I am able to raise a Shadow OnSelected event form the Custom Calendar that Raises the same event in the Year View. Can these three objects 'talk' to each other.
Most of the ArrayList samples use simple 1-dimension "Add("item") methods, and almost never show Removes. I would be very grateful for any help. Thanks!
|
|

October 18th, 2007, 07:48 PM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I finally got this implemented, but it was pretty difficult. I would like posts from anyone else who has used a class in an ArrayList, both adding and removing the class objects; also if anyone have ever overridden the SelectedDatesCollection of the base web Calendar Control.
Thanks
|
|

October 18th, 2007, 10:55 PM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It would be the first time posting for me. How do you load a bunch of classes?
|
|
 |