Calendar und DATETIME

banas

Grünschnabel
Hallo zusammen,

leider ist es mir bis jetzt nicht gelungen, den unten stehenden Code einwandfrei zum Laufen zu bringen. Ich hoffe es kann mir hier jemand helfen? Dargestellt wird ein Kalender der die Einträge einer Datenbank anzeigen soll. Im ersten Statement werden die Tage mit DB-Einträgen hervorgehoben. Nach der Auswahl eines Datums wird der Inhalt nicht angezeigt, weil auch eine Zeit hinterlegt ist. Ein Tip wäre echt super.

HTML:
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<HTML>
<HEAD>
<script language="VB" runat="server">

        Dim myconnection As SqlConnection
        Dim myda As SqlDataAdapter
        Dim ds As New DataSet()
        Dim dsSelDate As DataSet
 
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            myconnection = New SqlConnection("server=srvname;database=databasename;UID=userid;PWD=kennwort") 
			myda = New SqlDataAdapter("select right(convert(varchar(10), TAB_SPALTE1, 104), 10)as CHANGEDATE from TABELLE", myconnection)
            myda.Fill(ds, "CHANGEDATE")
        End Sub
        
        Protected Sub CalendarDRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs)
            'If the month is CurrentMonth
            If Not e.Day.IsOtherMonth Then
                Dim dr As DataRow
            For Each dr In ds.Tables(0).Rows
                'If EventDate is not Null
                 If Not dr("CHANGEDATE") Is DBNull.Value Then
                        Dim dtEvent As DateTime = dr("CHANGEDATE").ToString
                'If EventDate =CalendarDate
                If dtEvent.Equals(e.Day.Date) Then
                    e.Cell.BackColor = System.Drawing.Color.Pink
                End If
                End If
            Next
            'If the month is not CurrentMonth then hide the Dates
            Else
                e.Cell.Text = ""
        End If
End Sub

Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) '_
    myda = New SqlDataAdapter("select * from TABELLE where TAB_SPALTE1='" & _
        Calendar1.SelectedDate.ToString("yyyy-MM-dd") & "'", myconnection)
    dsSelDate = New DataSet()
    myda.Fill(dsSelDate, "TAB_SPALTE1")
    If dsSelDate.Tables(0).Rows.Count = 0 Then
                DataGrid1.Visible = True
        DataGrid1.DataSource = dsSelDate
        DataGrid1.DataBind()
    Else
        DataGrid1.Visible = True
        DataGrid1.DataSource = dsSelDate
        DataGrid1.DataBind()
    End If
 
End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
                <asp:Calendar id="Calendar1" runat="server" FirstDayOfWeek="Monday" 
                DayNameFormat="Short" Width=300 ShowDayHeader="True" ShowGridLines="True" 
                ShowNextPrevMonth="True" ShowTitle="True" selecteddaystyle-horizontalalign="Left" 
                selecteddaystyle-verticalalign="Top" selecteddaystyle-font-size="Small" 
                selecteddaystyle-forecolor="Red" OnDayRender="CalendarDRender" 
                OnSelectionChanged="Calendar1_SelectionChanged">
            <TodayDayStyle VerticalAlign="Top" BackColor="White"></TodayDayStyle>
            <DayStyle Font-Size="10" HorizontalAlign="center" VerticalAlign="Top" BackColor=WhiteSmoke></DayStyle>
            <NextPrevStyle ForeColor="Black" BackColor="LightSlateGray"></NextPrevStyle>
            <DayHeaderStyle ForeColor=RoyalBlue BackColor="Lavender"></DayHeaderStyle>
            <SelectedDayStyle Font-Size="10" HorizontalAlign="center" Font-Bold="True" ForeColor="Red"></SelectedDayStyle>
            <TitleStyle Font-Size="12" ForeColor=WhiteSmoke BackColor=LightSlateGray></TitleStyle>
            <WeekendDayStyle BackColor="PaleGoldenrod"></WeekendDayStyle>
            <OtherMonthDayStyle BackColor="Gainsboro"></OtherMonthDayStyle>
                </asp:Calendar></TD>
                <asp:DataGrid id="DataGrid1" Font-Size="XX-Small" Font-Names="Verdana" runat="server"></asp:DataGrid></TD>
        </form>
</body>
</HTML>

thx bn
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück