asp.net calendar - change date selector control

WONG Tony 161 Reputation points
2022-12-24T03:01:54.557+00:00

Can i select the date by clicking the cell of the date instead of the date character? Thanks.

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Albert Kallal 5,586 Reputation points
    2022-12-24T23:48:04.847+00:00

    Yes, you can add a "click" event to the cell.

    so, assuming this markup for the calendar:

    <asp:Calendar ID="Calendar1" runat="server" Height="751px" Width="1200px"   
        BorderColor="Black"  
        BorderStyle="Solid" BorderWidth="2px">  
        <DayHeaderStyle Height="40px" />  
        <DayStyle BorderStyle="Solid"  
            BorderColor="Black"  
            BorderWidth="1"  
            HorizontalAlign="Right"  
            VerticalAlign="Top" Height="80px" />  
        <OtherMonthDayStyle BackColor="LightSteelBlue" />  
        <SelectorStyle CssClass="btn-info" />  
        <TitleStyle Height="40px" />  
        <TodayDayStyle BackColor="LightSkyBlue" />  
        <WeekendDayStyle BackColor="Ivory" Height="60px" />  
    </asp:Calendar>  
    

    So, now in the day render event, you add this:

    Protected Sub Calendar1_DayRender(sender As Object, e As DayRenderEventArgs) Handles Calendar1.DayRender  
    
    
        If e.Day.IsSelected Then  
            e.Cell.BackColor = System.Drawing.Color.LightCoral  
        End If  
    
        e.Cell.Attributes.Add("OnClick", e.SelectUrl)  
    
    
    End Sub  
    

    And the day click event (date change), is this:

    Protected Sub Calendar1_SelectionChanged(sender As Object, e As EventArgs) Handles Calendar1.SelectionChanged  
    
        ' day sel  
        Debug.Print(Calendar1.SelectedDate)  
    
    End Sub  
    

    And now the result is this:

    273847-calclick.gif

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. WONG Tony 161 Reputation points
    2022-12-25T01:59:31.79+00:00

    fantastic!

    Merry Christmas!

    Thanks a lot for your help

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.