This is a migrated thread and some comments may be shown as answers.

Setting selectedDate property of RadCalendar

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Julian
Top achievements
Rank 1
Julian asked on 17 Feb 2009, 03:48 PM
I have a RadGrid that is using in place editing. One of my columns contains a RadCalendar control. I am setting the selectedDate of the RadCalendar to the value of a property 'ValidDate'.  I'm also setting the value of a Lable to the property 'ValidDate' as a sort of test. Initially when the Grid is displayed the label does have the correct value. However, when the 'edit' is clicked, causing the selected row to go into edit mode, the 'ValidDate' values I assigned to the label within the GridRow is lost.

Can you tell me why the value is lost and possibly how to correctly keep the value so I can set the selectedDate of the RadCalendar?

Thanks,

Here is the aspx code:

<rad:RadGrid ID="holidayRadGrid" AllowPaging="True" 
                    AllowSorting="True" GridLines="Horizontal" HorizontalAlign="Center" ShowFooter="true" 
                    ShowStatusBar="true" EnableAJAX="true" EnableAJAXLoadingTemplate="True" LoadingTemplateTransparency="25" 
                    AutoGenerateColumns="False" Skin="Grid" SkinsPath="~/App_Themes/VertexDefault" OnNeedDataSource="holidayRadGrid_NeedDataSource" 
                    OnUpdateCommand="holidayRadGrid_UpdateCommand" PageSize="18" runat="server"
                    <MasterTableView DataKeyNames="HolidayID,HolidayYear,HolidayDate,HolidayName" EditMode="InPlace" TableLayout="Auto" AllowNaturalSort="false" 
                        BorderColor="Black"
                        <Columns> 
                            <rad:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderStyle-Width="10px" /> 
                            <rad:GridBoundColumn HeaderStyle-Width="60px" DataField="HolidayName" HeaderText="Holiday" 
                                SortExpression="HolidayName" UniqueName="HolidayName" ReadOnly="true" /> 
                            <rad:GridTemplateColumn HeaderStyle-Width="100px" DataField="HolidayDate"  
                                SortExpression="HolidayDate" UniqueName="HolidayDate" > 
                                <ItemTemplate> 
                                    <asp:Label ID="holidayDateLabel" Text='<%# (DateTime) Eval("HolidayDate") == DateTime.MinValue ? ValidDate.ToString() : String.Format("{0:MM/dd/yyyy}", Eval("HolidayDate")) %>' runat="server" /> 
                                </ItemTemplate> 
                                <EditItemTemplate> 
                                   <asp:Calendar ID="holidayDateCalendar" SelectedDate='<%# (DateTime) Eval("HolidayDate") == DateTime.MinValue ? ValidDate : Eval("HolidayDate") %>'  VisibleDate='<%# (DateTime) Eval("HolidayDate") == DateTime.MinValue ? ValidDate : Eval("HolidayDate") %>' runat="server" /> 
                                </EditItemTemplate> 
                            </rad:GridTemplateColumn> 
                            <rad:GridBoundColumn DataField="HolidayID" UniqueName="HolidayID" ReadOnly="true" Display="false" /> 
                            <rad:GridBoundColumn DataField="HolidayYear" UniqueName="HolidayYear" ReadOnly="true" Display="false" /> 
                        </Columns> 
                    </MasterTableView> 
                    <ClientSettings> 
                                <ClientEvents OnGridCreated="holidayRadGridCreated" OnRowContextMenu="holidayRadGridRowContextMenu" /> 
                    </ClientSettings> 
                </rad:RadGrid> 
 
Here is the C# code:

private void BuildTable(int currentHolidayYear) 
        { 
            log.Debug("BuildTable"); 
 
            try 
            { 
                if (returns == null) 
                { 
                    // Create returns manager 
                    returns = ReturnsFactory.CreateReturns(); 
                } 
                 
                // Set 'Year' 
                validDate = new DateTime(Convert.ToInt32(holidayYear.SelectedValue), DateTime.Now.Month, DateTime.Now.Day); 
                 
                // Fetch Holidays 
                Holidays holidays = (Holidays)Session[Constants.Session.PageData]; 
                 
                // Get Holidays if they are not already in the session 
                if (holidays == null) 
                { 
                    holidays = returns.GetHolidays(currentHolidayYear); 
                    Session[Constants.Session.PageData] = holidays; 
                } 
 
                holidayRadGrid.DataSource = holidays.Values; 
                holidayRadGrid.DataBind(); 
 
                // Set correct year to be used for the column HolidayDate's Header Text 
                holidayRadGrid.MasterTableView.GetColumn("HolidayDate").HeaderText = holidayYear.SelectedValue; 
                holidayRadGrid.Rebind(); 
            } 
            catch (Exception ex) 
            { 
                log.Error("Error occurred in page '{0}'. Message: '{1}'", Request.Url.Segments[Request.Url.Segments.Length - 1], ex.Message); 
                Response.Redirect(Constants.Pages.ErrorPage); 
            } 
        } 
 
protected DateTime ValidDate 
        { 
            get { return validDate; } 
        } 
        #endregion 
 
#region Fields 
private DateTime validDate; 
#endregion 
 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Feb 2009, 08:09 AM
Hi Julian,

I am not sure where exactly you are calling the BuildTable function. If you are using the NeedDataSource event try calling it there . Also remove the DataBind() method in the BuildTable function.

Thanks
Shinu

0
Julian
Top achievements
Rank 1
answered on 18 Feb 2009, 03:02 PM
Shinu, Thank you very much. That solved my problem.

Tags
Grid
Asked by
Julian
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Julian
Top achievements
Rank 1
Share this question
or