I am attempting to do something similar to this but slightly different. I am attempting to put a raddatepicker in a radgrid filter template with the textbox disabled so the user cannot enter a date and must use the datepicker button. Then I want to have an imagebutton next to the datepicker that will clear the filter. The datepicker works as expected and filters the radgrid appropriately but clicking the imagebutton does not clear the filter. Here is my code for the column including javascript:
When I press the ClearOpenDateButton while the radgrid is filtered, I do get the partial page postback. The RadGrid_ItemCommand event is properly fired, the LinqDataSource Selecting and Selected events run correctly as well and in the Selected event, it does indeed indicate in the arguments that all rows are being returned from the datasource but the grid doesn't get updated. I'm thinking it's just an update problem but I'm not sure why it works fine with the raddatepicker but not the imagebutton.
Also when I press the ClearOpenDateButton, the datepicker does clear the selected date as expected.
<
telerik:GridTemplateColumn
DataField
=
"openDate"
DataType
=
"System.DateTime"
HeaderText
=
"Open Date"
SortExpression
=
"openDate"
UniqueName
=
"openDate"
ReadOnly
=
"True"
FilterControlAltText
=
"Filter open date"
>
<
HeaderStyle
Width
=
"150px"
/>
<
FilterTemplate
>
<
telerik:RadDatePicker
ID
=
"OpenedRadDatePicker"
runat
=
"server"
ClientEvents-OnDateSelected
=
"OpenDateSelected"
DbSelectedDate='<%# SetOpenedDate(Container) %>' DateInput-DisplayDateFormat="yyyy/MM/dd"
Culture="en-US">
<
Calendar
ID
=
"OpenedRadDatePickerCalendar"
runat
=
"server"
UseColumnHeadersAsSelectors
=
"False"
UseRowHeadersAsSelectors
=
"False"
ViewSelectorText
=
"x"
>
</
Calendar
>
<
DateInput
ID
=
"OpenedRadDatePickerDateInput"
runat
=
"server"
DateFormat
=
"yyyy/MM/dd"
DisplayDateFormat
=
"yyyy/MM/dd"
Enabled
=
"false"
>
<
ClientEvents
OnLoad
=
"OnClientLoad"
/>
</
DateInput
>
<
DatePopupButton
HoverImageUrl
=
""
ImageUrl
=
""
/>
<
ClientEvents
OnDateSelected
=
"OpenDateSelected"
/>
</
telerik:RadDatePicker
>
<
asp:ImageButton
ID
=
"ClearOpenDateButton"
runat
=
"server"
ImageUrl
=
"images/cancel.gif"
AlternateText
=
"Show All"
ToolTip
=
"Clear Open Date Filter"
Style
=
"vertical-align: middle"
Height
=
"15px"
Width
=
"15px"
OnClientClick
=
"ClearDateSelected(); return true;"
/>
<
telerik:RadScriptBlock
ID
=
"OpenDateSelectedRadScriptBlock"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
var datePicker;
function OnClientLoad(sender, args) {
datePicker = sender;
}
function ClearDateSelected() {
datePicker.clear();
}
function OpenDateSelected(sender, args) {
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
var date = FormatSelectedDate(sender);
var nextDate = GetNextSelectedDate(sender);
if (date != "" && nextDate != "") {
tableView.filter("openDate", date + " " + nextDate, Telerik.Web.UI.GridFilterFunction.Between);
}
else {
tableView.filter("openDate", "", Telerik.Web.UI.GridFilterFunction.NoFilter);
}
}
function FormatSelectedDate(picker) {
var formattedDate = "";
var date = picker.get_selectedDate();
if (date != null) {
var dateInput = picker.get_dateInput();
formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, "M/d/yyyy");
}
return formattedDate;
}
function GetNextSelectedDate(picker) {
var formattedDate = "";
var date = picker.get_selectedDate();
if (date != null) {
date.setDate(date.getDate() + 1);
var dateInput = picker.get_dateInput();
formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, "M/d/yyyy");
}
return formattedDate;
}
</
script
>
</
telerik:RadScriptBlock
>
</
FilterTemplate
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"openDateLabel"
Text='<%# Eval("openDate", "{0:yyyy/MM/dd}") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
protected DateTime? SetOpenedDate(GridItem item)
{
string openFilter = item.OwnerTableView.GetColumn("openDate").CurrentFilterValue;
if (string.IsNullOrEmpty(openFilter))
{
return new DateTime?();
}
else
{
return DateTime.Parse(openFilter.Substring(0, openFilter.IndexOf(" ")));
}
}
When I press the ClearOpenDateButton while the radgrid is filtered, I do get the partial page postback. The RadGrid_ItemCommand event is properly fired, the LinqDataSource Selecting and Selected events run correctly as well and in the Selected event, it does indeed indicate in the arguments that all rows are being returned from the datasource but the grid doesn't get updated. I'm thinking it's just an update problem but I'm not sure why it works fine with the raddatepicker but not the imagebutton.
Also when I press the ClearOpenDateButton, the datepicker does clear the selected date as expected.