asp.net calendar - change date selector control

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

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

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
1,173 questions
No comments
{count} votes

Accepted answer
  1. answered 2022-12-24T23:48:04.847+00:00
    Albert Kallal 3,446 Reputation points

    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

    No comments

1 additional answer

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

    fantastic!

    Merry Christmas!

    Thanks a lot for your help

    No comments