Populating a Calendar from a Database

J

jmhmaine

I have a table SQL Server View that contains information, including dates
that I want to represent in a Calendar. specifically, for each row in the
view, I want to create a Note for that event in the Calendar. Since there
isn't a databind option so I realize I need to use the _DayRender event.

Since the _DayRender event is called for the creation of each cell, I want
to make sure I iterate through the rows efficiently. How should I construct
the _DayRender event? Thanks.
 
J

jmhmaine

I found an interesting code sample at:
http://odetocode.com/Articles/223.aspx

I'm trying to adapt and port it over to VB, I have the following so far for
the _DayRender event:

Public Sub c1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)
Dim rows() As DataRow = _dt.Select(String.Format("Date >= #{0}# AND Date <
#{1}#", e.Day.Date.ToShortDateString(),
e.Day.Date.AddDays(1).ToShortDateString()))

For Each row As DataRow In rows
e.Cell.Text = CType(row("StoryName"), String)
Next

End Sub

The problem is I'm receiving an the following error on the Dim rows() line:
Object reference not set to an instance of an object.
 
S

Steven Cheng[MSFT]

Hi Jmh,

Welcome to ASPNET newsgroup.
From the further error message and code snippet you provide, seem the
problem was caused by "Null Reference", the DataRow() retrieved from the
DataTable.Select method return nothing. Have you checked whether that
select statement has any valid rows to match?

If there is any further problems, please feel free to post here. Thanks,


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

jmhmaine

Steven:

The select will be empty on most days, only 3 or 4 days out of the month
will have events. So is there a better way of populating select days in a
Calendar from a database? Thanks.

Josh.
 
J

jmhmaine

I figured it out, I wasn't loading the datatable object. I would still like
to know if there is a better way to populate a Calendar object from a
Database. Thanks.

Josh.
 
S

Steven Cheng[MSFT]

Hi Jmh,

Thanks for the followup. I haven't found any other simler means for
databinding the Calendar since it's not a normal template databound control
like datagrid or dataslist. The only means currently is using the
DayREnder event to customize the DAy Cell. Also, here is a certain web
artcile I've found:

#Using Calendar Control in ASP.NET
http://www.c-sharpcorner.com/Code/2003/July/ASPNetCalendarControl.asp

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

jmhmaine

In that article they iterate each row in the dataset table. In the article I
found the author performs a select to find the date. I wonder which has
better performance. I'll setup both and look at the results with tracing.
Thanks.

Josh.
 
J

jmhmaine

Steven:

The second technique you pointed out took about 1/3 less time to render.
Thanks.

Josh.
 
S

Steven Cheng[MSFT]

Glad that you've found the proper choice.

Good LUck!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

jmhmaine

I realized after testing that the results might be different using a larger
resultset, I was testing with a resultset of only 10 records. If I have time
to perform additional testing, I'll post the results here.

Josh.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top