I have the following code (to find) the raddatepicker control within the radgrid, so that I can attach a onblur event to it. I am getting object reference exception within the c# code. Can someone please tell me what am I doing wrong ? these statements always return null - RadDatePicker StartDate = (RadDatePicker)e.Item.FindControl("radBillPeriodStartDate1");
| <telerik:RadGrid ID="gridInvLines" AllowPaging="False" Skin="Office2007" |
| runat="server" AutoGenerateColumns="False" DataSourceID="odsInvLines" |
| GridLines="None" OnItemCommand="gridInvLines_ItemCommand" OnItemDataBound="gridInvLines_ItemDataBound" ShowFooter="True"> |
| <ClientSettings > |
| <ClientEvents OnKeyPress="disableEnterKey" OnPopUpShowing="PopUpShowing" /> |
| </ClientSettings> |
| <MasterTableView DataKeyNames="LINE_NUMBER" DataSourceID="odsInvLines" EditMode="PopUp" InsertItemDisplay="Top" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add New Line"> |
| <Columns> |
| <telerik:GridTemplateColumn HeaderText="Billing Period Start Date" UniqueName="BEGIN_BILLING_PERIOD_COLUMN" |
| EditFormColumnIndex="1"> |
| <HeaderStyle Width="62px" HorizontalAlign="Center" /> |
| <ItemTemplate> |
| <asp:Label runat="server" ID="lblBillingPeriodStartDate" Text='<%# Eval("BEGIN_BILLING_PERIOD", "{0:D}") %>'></asp:Label> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <telerik:RadDatePicker ID="radBillPeriodStartDate1" Skin="Office2007" Style="vertical-align: middle;" |
| runat="server" |
| DbSelectedDate='<%# Bind("BEGIN_BILLING_PERIOD", "{0:d}") %>' |
| MinDate='<%# DateTime.Now.AddMonths(Convert.ToInt32(ConfigurationManager.AppSettings["BillingMin"].ToString()))%>' |
| MaxDate='<%# DateTime.Now.AddMonths(Convert.ToInt32(ConfigurationManager.AppSettings["BillingMax"].ToString()))%>' |
| > |
| <Calendar ShowRowHeaders="false"> |
| <OutOfRangeDayStyle Font-Strikeout="true" ForeColor="red" /> |
| </Calendar> |
| <DateInput ID="DateInput1" runat="server" InvalidStyle-BorderColor="red" InvalidStyle-ForeColor="red" EmptyMessageStyle-BorderColor="red" EmptyMessage=" "> |
| <ClientEvents OnKeyPress="disableEnterKey" /> |
| </DateInput> |
| </telerik:RadDatePicker> |
| <asp:RequiredFieldValidator ID="rfvBillPeriodstartDate" runat="server" ControlToValidate="radBillPeriodStartDate1" |
| ErrorMessage="Billing Period Start Date must be within the range of 18 months in the past or 2 months in the future">*</asp:RequiredFieldValidator> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn HeaderText="Billing Period End Date" UniqueName="END_BILLING_PERIOD_COLUMN" |
| EditFormColumnIndex="1"> |
| <HeaderStyle Width="62px" HorizontalAlign="Center" /> |
| <ItemTemplate> |
| <asp:Label runat="server" ID="lblBillingPeriodEndDate" Text='<%# Eval("END_BILLING_PERIOD", "{0:D}") %>'></asp:Label> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <asp:TextBox ID="txtDate1" runat="server"></asp:TextBox> |
| <telerik:RadDatePicker ID="radBillPeriodEndDate1" Skin="Office2007" Style="vertical-align: middle;" |
| runat="server" DbSelectedDate='<%# Bind("END_BILLING_PERIOD", "{0:d}") %>' |
| MinDate='<%# DateTime.Now.AddMonths(Convert.ToInt32(ConfigurationManager.AppSettings["BillingMin"].ToString()))%>' |
| MaxDate='<%# DateTime.Now.AddMonths(Convert.ToInt32(ConfigurationManager.AppSettings["BillingMax"].ToString()))%>' |
| > |
| <Calendar ShowRowHeaders="false"> |
| <OutOfRangeDayStyle Font-Strikeout="true" ForeColor="red" /> |
| </Calendar> |
| <DateInput ID="DateInput2" runat="server" InvalidStyle-BorderColor="red" InvalidStyle-ForeColor="red" EmptyMessageStyle-BorderColor="red" EmptyMessage=" "> |
| <ClientEvents OnKeyPress="disableEnterKey" /> |
| </DateInput> |
| </telerik:RadDatePicker> |
| <asp:RequiredFieldValidator ID="rfvBillPeriodEndDate" runat="server" ControlToValidate="radBillPeriodEndDate1" |
| ErrorMessage="Billing Period End Date must be within the range of 18 months in the past or 2 months in the future">*</asp:RequiredFieldValidator> |
| <asp:CompareValidator ID="cvEndDate" runat="server" ControlToValidate="radBillPeriodEndDate1" |
| ControlToCompare="radBillPeriodStartDate1" Display="None" Operator="GreaterThanEqual" |
| Type="Date" ErrorMessage="Billing Periond End Date must be great than or equal to Billing Period Start Date">*</asp:CompareValidator> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| <PopUpSettings Modal="true" Width="600" /> |
| </EditFormSettings> |
| </MasterTableView> |
| <ValidationSettings CommandsToValidate="PerformInsert,Update" /> |
| </telerik:RadGrid> |
| protected void gridInvLines_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem) |
| { |
| //both these controls return null |
| RadDatePicker StartDate = (RadDatePicker)e.Item.FindControl("radBillPeriodStartDate1"); |
| RadDatePicker EndDate = (RadDatePicker)e.Item.FindControl("radBillPeriodEndDate1"); |
| StartDate.DateInput.Attributes.Add("onblur", string.Format("changeEndDate('{0}','{1}');", StartDate.ClientID, EndDate.ClientID)); |
| } |
| } |
