Results 1 to 7 of 7

Thread: How would I use a calendar to highlight different days from database?

  1. #1

    Thread Starter
    Member Comn8u's Avatar
    Join Date
    Jul 2004
    Posts
    35

    How would I use a calendar to highlight different days from database?

    How would I pull dates from a database to show up highlighted on a calendar? What I mean by this is, I have a calendar that shows each day of the month and I have certain days that I want to have highlighted so visitors will know to click on them instead of every day in the month.

    If there are highlighted days, visitors will know which days to click on instead of clicking on random days.

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    From my limited use of calender controls i don't think this would be possible.

    I reckon you'll probably have to code your own calender control to do this.

    But as usual i wait to be proven wrong.

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Like my calendar for my blog?
    www.variantx.com

    I have the code I use if you want it, I pull the information based off the month selected, find the days that have valid info, then I make links from each of the days that are valid. The rest are disabled. Just finished it up last week.

  4. #4

    Thread Starter
    Member Comn8u's Avatar
    Join Date
    Jul 2004
    Posts
    35
    That's exactly what I'm looking for, can you give me some ideas on how to do it?

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I will give you the code as soon as I get my other machine up that has the code on it... stand by.

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Code:
    int[] days;  // Holds the days to render for display.
    
    private void Page_Load(object sender, System.EventArgs e)
    {
    	// Need this to set the current date of the calendar.  If this isn't done
    	// and a user selects to see a months view, the min date will be returned
    	// because it isn't initialized.
    	if(!Page.IsPostBack)
    	{
    		calBlog.VisibleDate = DateTime.Today;
    		SetBlogDates(DateTime.Now);
    	}		
    }
    
    private void calBlog_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
    {
    	bool matched = false;
    
    	// Add custom text to cell in the Calendar control.
    	if(days != null)
    	{
    		foreach(int d in days)
    		{
    			if (e.Day.Date.Day == d && !e.Day.IsOtherMonth)
    			{
    				e.Cell.BackColor = Color.LightSteelBlue;
    				matched = true;
    			}
    		}
    	}
    
    	if(!matched)
    	{
    		e.Cell.BackColor = Color.White;
    		e.Day.IsSelectable = false;
    	}
    }
    
    private void calBlog_SelectionChanged(object sender, System.EventArgs e)
    {
    	Response.Redirect("BlogDay.aspx?Date=" + HttpUtility.UrlEncode(calBlog.SelectedDate.ToShortDateString()));
    }
    
    private void lbtnMonthView_Click(object sender, System.EventArgs e)
    {
    	Response.Redirect("BlogMonth.aspx?Date=" + HttpUtility.UrlEncode(calBlog.VisibleDate.ToShortDateString()));
    }
    
    private void calBlog_VisibleMonthChanged(object sender, System.Web.UI.WebControls.MonthChangedEventArgs e)
    {
    	SetBlogDates(e.NewDate);
    }
    
    private void SetBlogDates(DateTime dt)
    {
    	BlogPostCollection bpCol = BlogPostManager.GetBlogPostByMonth(dt, General.ConnectionString);
    	ArrayList temp = new ArrayList();
    	bool alreadyIn = false;
    	foreach(BlogPost bp in bpCol)
    	{
    		foreach(object itm in temp)
    		{
    			if(bp.DatePosted.Day == (int)itm)
    				alreadyIn = true;
    		}
    
    		if(alreadyIn)
    			alreadyIn = false;
    		else
    			temp.Add(bp.DatePosted.Day);
    	}
    	days = new int[temp.Count];
    
    	for(int i = 0; i < temp.Count; i++)
    		days[i] = (int)temp[i];
    }

  7. #7

    Thread Starter
    Member Comn8u's Avatar
    Join Date
    Jul 2004
    Posts
    35
    Thanks, but I need code for VB.net. That is C#. I'm sure I can just try and convert it to VB.net somehow.

    Thanks for your time
    It's not the size of the dog in the fight, it's the size of the fight in the dog.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width