radDatePicker not reachable from code behind

3 posts, 1 answers
  1. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 11 Apr 2014 Link to this post

    Asp.net Ajax in an asp page, I am on Q1 2014 update.
    I have this page with a radpicker in the editForm template (radDatePicker1):
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="members_Default" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <style type="text/css">
            .auto-style1 {
                width: 100%;
            }
        </style>
    </head>
    <body>
     
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <Scripts>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js"></asp:ScriptReference>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js"></asp:ScriptReference>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js"></asp:ScriptReference>
                </Scripts>
            </telerik:RadScriptManager>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WTAConnectionString %>" DeleteCommand="DELETE FROM [Tempi] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Tempi] ([Date], [Pnum], [WorkedTime], [Note], [Week], [hours], [minutes]) VALUES (@Date, @Pnum, @WorkedTime, @Note, @Week, @hours, @minutes)" SelectCommand="SELECT * FROM [Tempi]" UpdateCommand="UPDATE [Tempi] SET [Date] = @Date, [Pnum] = @Pnum, [WorkedTime] = @WorkedTime, [Note] = @Note, [Week] = @Week, [hours] = @hours, [minutes] = @minutes WHERE [Id] = @Id">
                <DeleteParameters>
                    <asp:Parameter Name="Id" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter DbType="Date" Name="Date" />
                    <asp:Parameter Name="Pnum" Type="String" />
                    <asp:Parameter DbType="Time" Name="WorkedTime" />
                    <asp:Parameter Name="Note" Type="String" />
                    <asp:Parameter Name="Week" Type="String" />
                    <asp:Parameter Name="hours" Type="Int32" />
                    <asp:Parameter Name="minutes" Type="Int32" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter DbType="Date" Name="Date" />
                    <asp:Parameter Name="Pnum" Type="String" />
                    <asp:Parameter DbType="Time" Name="WorkedTime" />
                    <asp:Parameter Name="Note" Type="String" />
                    <asp:Parameter Name="Week" Type="String" />
                    <asp:Parameter Name="hours" Type="Int32" />
                    <asp:Parameter Name="minutes" Type="Int32" />
                    <asp:Parameter Name="Id" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:WTAConnectionString %>" SelectCommand="SELECT [Pnum] FROM [Pnum]"></asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:WTAConnectionString %>" SelectCommand="SELECT [minutes] FROM [helper]"></asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:WTAConnectionString %>" SelectCommand="SELECT [hours] FROM [helper]"></asp:SqlDataSource>
            <link href="../css/StyleSheet.css" rel="stylesheet" />
            <div>
                Time Management - Registered Users
            </div>
            <table class="auto-style1">
                <tr>
                    <td class="left"></td>
                    <td class="center"></td>
                    <td class="right"></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td> </td>
                    <td>
                        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" Culture="it-IT" DataSourceID="SqlDataSource1" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" Skin="Outlook" CellSpacing="-1" GridLines="Both">
                            <ExportSettings>
                                <Pdf PageWidth="">
                                </Pdf>
                            </ExportSettings>
                            <ClientSettings>
                                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                            </ClientSettings>
                            <MasterTableView DataKeyNames="Id" DataSourceID="SqlDataSource1" CommandItemDisplay="Top">
                                <RowIndicatorColumn Visible="False">
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn Created="True">
                                </ExpandCollapseColumn>
                                <Columns>
                                    <telerik:GridEditCommandColumn ButtonType="ImageButton">
                                        <HeaderStyle Width="35px" />
                                    </telerik:GridEditCommandColumn>
                                    <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column" HeaderText="Id" ReadOnly="True" SortExpression="Id" UniqueName="Id">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text="" />
                                        </ColumnValidationSettings>
                                        <HeaderStyle Width="60px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridDateTimeColumn DataField="Date" DataType="System.DateTime" FilterControlAltText="Filter Date column" HeaderText="Date" SortExpression="Date" UniqueName="Date" DataFormatString="{0:dd/MM/yyyy}">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text="" />
                                        </ColumnValidationSettings>
                                        <HeaderStyle Width="80px" />
                                    </telerik:GridDateTimeColumn>
                                    <telerik:GridDropDownColumn DataField="Pnum" DataSourceID="SqlDataSource2" ListTextField="Pnum" ListValueField="Pnum" FilterControlAltText="Filter column column" UniqueName="column" HeaderText="P-Number">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text="" />
                                        </ColumnValidationSettings>
                                        <HeaderStyle Width="80px" />
                                    </telerik:GridDropDownColumn>
                                    <telerik:GridBoundColumn DataField="WorkedTime" DataType="System.TimeSpan" FilterControlAltText="Filter WorkedTime column" HeaderText="Worked Time" SortExpression="WorkedTime" UniqueName="WorkedTime">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text="" />
                                        </ColumnValidationSettings>
                                        <HeaderStyle Width="90px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Week" FilterControlAltText="Filter Week column" HeaderText="Week" SortExpression="Week" UniqueName="Week">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text="" />
                                        </ColumnValidationSettings>
                                        <HeaderStyle Width="60px" />
                                    </telerik:GridBoundColumn>
                                    <telerik:GridDropDownColumn DataField="minutes" DataSourceID="SqlDataSource3" ListTextField="minutes" ListValueField="minutes" FilterControlAltText="Filter minutes column" UniqueName="minutes" HeaderText="Minutes" DataType="System.Int16">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text="" />
                                        </ColumnValidationSettings>
                                        <HeaderStyle Width="80px" />
                                    </telerik:GridDropDownColumn>
                                    <telerik:GridDropDownColumn DataField="hours" DataSourceID="SqlDataSource4" ListTextField="hours" ListValueField="hours" FilterControlAltText="Filter hours column" UniqueName="hours" HeaderText="Hours" DataType="System.Int16">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text="" />
                                        </ColumnValidationSettings>
                                        <HeaderStyle Width="80px" />
                                    </telerik:GridDropDownColumn>
                                    <telerik:GridBoundColumn DataField="Note" FilterControlAltText="Filter Note column" HeaderText="Note" SortExpression="Note" UniqueName="Note">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text="" />
                                        </ColumnValidationSettings>
                                    </telerik:GridBoundColumn>
                                    <telerik:GridButtonColumn ButtonType="ImageButton" Text="Delete" CommandName="Delete" FilterControlAltText="Filter column1 column" ConfirmDialogType="RadWindow" ConfirmText="Do you really want to delete this project and all its content?" UniqueName="column1">
                                        <HeaderStyle Width="30px" />
                                    </telerik:GridButtonColumn>
                                </Columns>
                                <EditFormSettings EditFormType="Template">
                                    <EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
                                    <FormTemplate>
                                        <table class="table">
                                            <tr>
                                                <td class="left"></td>
                                                <td class="center" colspan="2"></td>
                                                <td class="right"></td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td class="topBorder">
                                                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                                                </td>
                                                <td class="topBorder"> </td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td class="centerLeft">
                                                    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" Culture="it-IT"  MaxDate="2020-12-31" MinDate="2013-01-01" Skin="Outlook" Calendar-CultureInfo="it-IT">
                                                        <Calendar UseRowHeadersAsSelectors="False" runat="server" UseColumnHeadersAsSelectors="False" EnableWeekends="True" Culture="it-IT" FastNavigationNextText="&lt;&lt;" Skin="Outlook"></Calendar>
     
                                                        <DateInput runat="server" DisplayDateFormat="dd/MM/yyyy" DateFormat="dd/MM/yyyy" LabelWidth="40%">
                                                            <EmptyMessageStyle Resize="None"></EmptyMessageStyle>
     
                                                            <ReadOnlyStyle Resize="None"></ReadOnlyStyle>
     
                                                            <FocusedStyle Resize="None"></FocusedStyle>
     
                                                            <DisabledStyle Resize="None"></DisabledStyle>
     
                                                            <InvalidStyle Resize="None"></InvalidStyle>
     
                                                            <HoveredStyle Resize="None"></HoveredStyle>
     
                                                            <EnabledStyle Resize="None"></EnabledStyle>
                                                        </DateInput>
     
     
                                                    </telerik:RadDatePicker>
                                                </td>
                                                <td class="centerRight">
                                                    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
                                                </td>
                                                <td> </td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td> </td>
                                                <td> </td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td >
                                                    <telerik:RadDropDownList ID="RadDropDownList1" runat="server" Skin="Outlook">
                                                    </telerik:RadDropDownList>
                                                </td>
                                                <td> </td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td > </td>
                                                <td> </td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td>
                                                    <telerik:RadDropDownList ID="RadDropDownList2" runat="server" Skin="Outlook">
                                                    </telerik:RadDropDownList>
                                                </td>
                                                <td >
                                                    <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
                                                </td>
                                                <td> </td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td> </td>
                                                <td> </td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td>
                                                    <telerik:RadDropDownList ID="RadDropDownList3" runat="server" Skin="Outlook">
                                                    </telerik:RadDropDownList>
                                                </td>
                                                <td> </td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td> </td>
                                                <td> </td>
                                                <td> </td>
                                            </tr>
                                            <tr>
                                                <td> </td>
                                                <td >
                                                    <telerik:RadTextBox ID="RadTextBox1" runat="server" Height="45px" Width="100%" Skin="Outlook">
                                                    </telerik:RadTextBox>
                                                </td>
                                                <td> </td>
                                            </tr>
                                        </table>
                                    </FormTemplate>
     
     
     
                                </EditFormSettings>
                            </MasterTableView>
                        </telerik:RadGrid>
                    </td>
                    <td> </td>
                </tr>
                <tr>
                    <td> </td>
                    <td> </td>
                    <td> </td>
                </tr>
                <tr>
                    <td> </td>
                    <td> </td>
                    <td> </td>
                </tr>
            </table>
        </form>
    </body>
    </html>

    I am trying to set today date as default using this code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    public partial class members_Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadDatePicker1.SelectedDate = DateTime.Now.Date;   
       
        }
         
    }
    I get the error message "Unknown entity RadDatePicker1". So basically it is not reachable in code behind.
    I saved, rebuild, rebooted, update, but the problem is still there. I can I solve this problem?
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Apr 2014 in reply to Felice Link to this post

    Hi Felice,

    In order to access the RadDatePicker inside the EditForm of RadGrid, you need to write the code in the OnItemDataBound event of RadGrid as follows.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            RadDatePicker picker = item.FindControl("RadDatePicker1") as RadDatePicker;
            //your code
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 14 Apr 2014 in reply to Shinu Link to this post

    Thats perfect! 
    Thank you Shinu.
Back to Top