0

Hello,

I have a detailsview control on my page with a template field for the date. I wanted a pop up calendar control to populate the date so I added that:

<asp:DetailsView ID="addEventDetailView" runat="server" Height="50px" Width="503px"
            DataSourceID="eventDataSource" AutoGenerateRows="False" DataKeyNames="eventAuid"
            DefaultMode="Insert" CellPadding="4" ForeColor="#333333" GridLines="None" OnItemInserting="addEventDetailView_ItemInserting"
            OnPageIndexChanging="addEventDetailView_PageIndexChanging" OnItemInserted="addEventDetailView_ItemInserted">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
            <RowStyle BackColor="#EFF3FB" />
            <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <Fields>
                <asp:BoundField DataField="eventAuid" HeaderText="eventAuid" InsertVisible="False"
                    ReadOnly="True" SortExpression="attendeeAuid" />
                <asp:BoundField DataField="eventName" HeaderText="Event Name" SortExpression="Event Name" />
                <asp:BoundField DataField="description" HeaderText="Description Of Event" SortExpression="Description Of Event" />
                <asp:BoundField DataField="host" HeaderText="host" SortExpression="host" Visible="False"
                    InsertVisible="False" />
                <asp:TemplateField HeaderText="Registration Close Date" SortExpression="Registration Close Date">
                    <EditItemTemplate>
                        <asp:TextBox ID="eventRegistrationClosedTxt" runat="server" Text='<%# Bind("eventRegistrationClosed") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="eventRegistrationClosedTxt" runat="server" AutoPostback="false" Text='<%# Bind("eventRegistrationClosed") %>'></asp:TextBox>
                        <asp:ImageButton ID="calendarImageBtn" runat="server" ImageUrl="~/Images/Calendar_schedule.png" onclick="calendarImageBtn_Click"/>
                        <asp:Calendar ID="eventRegistrationClosedCalendar" runat="server" Visible="false" SelectionChanged="eventRegistrationClosedCalendar_SelectionChanged">
                        </asp:Calendar>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="eventRegistrationClosedLbl" runat="server" Text='<%# Bind("eventRegistrationClosed") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField ShowHeader="False">
                    <InsertItemTemplate>
                        <asp:Button ID="saveBtn" runat="server" CausesValidation="True" CommandName="Insert"
                            Text="Save" />&nbsp;<asp:Button ID="cancelBtn" runat="server" CausesValidation="False"
                                CommandName="Cancel" OnClick="cancelBtn_Click" Text="Cancel" />
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Button ID="saveBtn" runat="server" CausesValidation="False" CommandName="New"
                            Text="Save" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Fields>
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:DetailsView>

then my c# code:

protected void calendarImageBtn_Click(object sender, EventArgs e)
        {
            Calendar cal = (Calendar)addEventDetailView.FindControl("eventRegistrationClosedCalendar");
            cal.Visible = true;

        }
        protected void eventRegistrationClosedCalendar_SelectionChanged(object sender, EventArgs e)
        {
            Calendar calendar = (Calendar)addEventDetailView.FindControl("eventRegistrationClosedCalendar");
            TextBox eventTxt = (TextBox)addEventDetailView.FindControl("eventRegistrationClosedTxt");
            eventTxt.Text = calendar.SelectedDate.ToShortDateString();
            calendar.Visible = false;
        }

The image button does pop up the calendar but when I select a date it does nothing. Can someone maybe tell me why it is not working?

Thank you,
Jess

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Jesi523
0

I found it, the SelectionChanged event on the calendar should have been onSelectionChanged, thanks though.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.