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

Grid Export Error after filter data

0 Answers 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
marwat
Top achievements
Rank 1
marwat asked on 15 Feb 2017, 07:01 AM

Hi,

I have a RadGrid with ExportToExcel functionality. That works very well.

My problem:

When I filter the data by EndDate (data between two EndDates). Then clicking on ExportToExcel button gives error "The string was not recognized as a valid DateTime."

Here's my markup:

01.<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
02.    <script type="text/javascript">
03.        function requestStart(sender, args) {
04.            if (args.get_eventTarget().indexOf("DownloadPDF") > 0 || args.get_eventTarget().indexOf("ExportToExcelButton") >= 0)
05.                args.set_enableAjax(false);
06.        }
07.    </script>
08.    <telerik:radgrid id="grdView" runat="server" skinid="grdViewSkin" autogeneratecolumns="False"
09.        cellspacing="0" gridlines="None" showgrouppanel="true" allowmultirowselection="true"
10.        onneeddatasource="grdView_NeedDataSource">
11. <MasterTableView HierarchyLoadMode="ServerOnDemand" HierarchyDefaultExpanded="false" DataKeyNames="ID" >
12.  <Columns>
13.     <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterControlAltText="Filter ID" HeaderText="ID" UniqueName="ID"></telerik:GridBoundColumn>
14.     <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name" HeaderText="Name" UniqueName="Name" ></telerik:GridBoundColumn>
15.     <telerik:GridDateTimeColumn DataField="StartDate" DataFormatString="{0:MM/dd/yy}" DataType="System.DateTime"
16.                                 FilterControlAltText="Filter StartDate" HeaderText="StartDate" UniqueName="StartDate"></telerik:GridDateTimeColumn>
17.     <telerik:GridDateTimeColumn DataField="EndDate"   DataFormatString="{0:MM/dd/yy}" DataType="System.DateTime" HeaderText="EndDate"  UniqueName="EndDate">
18.         <FilterTemplate>
19.             <telerik:RadDatePicker ID="dateFrom" runat="server" >
20.                 <ClientEvents OnDateSelected="FromDateSelected" />
21.              </telerik:RadDatePicker>
22.                  To
23.              <telerik:RadDatePicker ID="dateTo" runat="server" Width="30px">
24.                 <ClientEvents OnDateSelected="ToDateSelected" />
25.              </telerik:RadDatePicker>                           
26.              <telerik:RadScriptBlock ID="scriptFilterEventDate" runat="server">
27.                 <script type="text/javascript">
28.                     function FromDateSelected(sender, args) {
29.                         var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
30.                         var ToPicker = $find('<%# ((GridItem)Container).FindControl("dateTo").ClientID %>');
31. 
32.                         var fromDate = FormatSelectedDate(sender);
33.                         var toDate = FormatSelectedDate(ToPicker);
34. 
35.                         if (toDate != '') {
36.                             tableView.filter("ContractEndDate", fromDate + " " + toDate, "Between");
37.                         }
38.                     }
39. 
40.                     function ToDateSelected(sender, args) {
41.                         var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
42.                         var FromPicker = $find('<%# ((GridItem)Container).FindControl("dateFrom").ClientID %>');
43. 
44.                         var fromDate = FormatSelectedDate(FromPicker);
45.                         var toDate = FormatSelectedDate(sender);
46. 
47.                         if (fromDate != '') {
48.                             tableView.filter("ContractEndDate", fromDate + " " + toDate, "Between");
49.                         }
50.                     }
51. 
52.                     function FormatSelectedDate(picker) {
53.                         var date = picker.get_selectedDate();
54.                         var dateInput = picker.get_dateInput();
55.                         var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());
56. 
57.                         return formattedDate;
58.                     }
59.               </script>
60.              </telerik:RadScriptBlock>
61.         </FilterTemplate>
62.   </telerik:GridDateTimeColumn>  
63.   </Columns>
64.   </MasterTableView
65.   </telerik:radgrid>
66.</asp:Content>

 

Is there something I'm missing?

 

No answers yet. Maybe you can help?

Tags
Grid
Asked by
marwat
Top achievements
Rank 1
Share this question
or