Populating a Calendar from a Database

Discussion in 'ASP .Net Web Controls' started by jmhmaine, Mar 1, 2005.

  1. jmhmaine

    jmhmaine Guest

    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.
     
    jmhmaine, Mar 1, 2005
    #1
    1. Advertising

  2. jmhmaine

    jmhmaine Guest

    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.
     
    jmhmaine, Mar 1, 2005
    #2
    1. Advertising

  3. 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.)
     
    Steven Cheng[MSFT], Mar 2, 2005
    #3
  4. jmhmaine

    jmhmaine Guest

    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.

    "Steven Cheng[MSFT]" wrote:

    > 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.)
    >
    >
     
    jmhmaine, Mar 2, 2005
    #4
  5. jmhmaine

    jmhmaine Guest

    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.

    "jmhmaine" wrote:

    > 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.
    >
    > "Steven Cheng[MSFT]" wrote:
    >
    > > 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.)
    > >
    > >
     
    jmhmaine, Mar 2, 2005
    #5
  6. 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.)
     
    Steven Cheng[MSFT], Mar 3, 2005
    #6
  7. jmhmaine

    jmhmaine Guest

    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.

    "Steven Cheng[MSFT]" wrote:

    > 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.)
    >
    >
     
    jmhmaine, Mar 3, 2005
    #7
  8. jmhmaine

    jmhmaine Guest

    Steven:

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

    Josh.

    "jmhmaine" wrote:

    > 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.
    >
    > "Steven Cheng[MSFT]" wrote:
    >
    > > 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.)
    > >
    > >
     
    jmhmaine, Mar 3, 2005
    #8
  9. 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.)
     
    Steven Cheng[MSFT], Mar 4, 2005
    #9
  10. jmhmaine

    jmhmaine Guest

    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.

    "Steven Cheng[MSFT]" wrote:

    > 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.)
    >
    >
     
    jmhmaine, Mar 4, 2005
    #10
  11. Thank you Josh,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Mar 7, 2005
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hazzard
    Replies:
    3
    Views:
    5,063
    Hazzard
    Jul 14, 2003
  2. TB
    Replies:
    5
    Views:
    2,866
  3. RAB
    Replies:
    4
    Views:
    548
    MamaKike
    Nov 18, 2005
  4. Replies:
    2
    Views:
    345
    Jason King
    May 24, 2006
  5. Carlos Albert

    Populating Menu Control from DataBase

    Carlos Albert, Jun 13, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    5,529
    Carlos Albert
    Jun 13, 2006
Loading...

Share This Page