I have a RadComboBox using ItemTemplate to show list of date range, which has two columns, rangName and from-end dates. In footer template, there are two RadDatePicker to select custom from/end date, onDateSelected in toDatePicker client event, the custom from/end date is to add into RadComboBoxItem. However, after added the item, only Item.Text is shown, Item.value can't be shown next to text in itemtemplate. How to add a new item into ItemTemplate, or databind in client side?
function ToDateSelected(sender, eventArgs) { |
AddCustomPostDt(); |
} |
function AddCustomPostDt() { |
var combo = $find("<%=RadComboBoxPostDt.ClientID %>"); |
var picker1 = $find('<%=fromDatePicker.ClientID %>'); |
var picker2 = $find('<%=toDatePicker.ClientID %>'); |
var fromDate = picker1.get_selectedDate(); |
var toDate = picker2.get_selectedDate(); |
if ( fromDate == null ) { |
return; |
} |
if (toDate == null) { |
return; |
} |
var isExisted = false; |
var item; |
if (combo.findItemByText("Custom")) { |
isExisted = true; |
item = combo.findItemByText("Custom"); |
} |
else { |
item = new Telerik.Web.UI.RadComboBoxItem(); |
} |
var desc = fromDate.format("M/dd/yyyy") + " - " + toDate.format("M/dd/yyyy"); |
item.set_value(desc); |
combo.trackChanges(); |
if (!isExisted) { |
item.set_text("Custom"); |
combo.get_items().add(item); |
} |
item.select(); |
combo.commitChanges(); |
combo.hideDropDown; |
} |
<telerik:RadComboBox |
ID="RadComboBoxPostDt" |
MarkFirstMatch="True" |
runat="server" |
Height="165px" |
Width="400px" |
Skin="Default" |
AutoPostBack="False" |
HighlightTemplatedItems="True" |
ShowToggleImage="True" |
ZIndex="5000" |
AppendDataBoundItems="true" |
OnClientSelectedIndexChanged="PostDtCombo_OnClientSelectedIndexChanged" |
OnClientDropDownClosing="OnClientDropDownClosing"> |
<ItemTemplate> |
<table style="border-bottom: 1px dotted #EFEFEF; margin-bottom: 6px; font-size: 11px;" width="98%"> |
<tr> |
<td width="150px"> |
<%# DataBinder.Eval(Container, "Text") %> |
</td> |
<td> |
<%# DataBinder.Eval(Container, "Value") %> |
</td> |
</tr> |
</table> |
</ItemTemplate> |
<HeaderTemplate> |
<table style="border-bottom: 1px dotted #EFEFEF; margin-bottom: 10px; font-size: 11px;" width="98%"> |
<tr> |
<td> |
<asp:Label ID="DateRangeLabel" runat="server"><b>Standard:</b></asp:Label> |
</td> |
</tr> |
</table> |
</HeaderTemplate> |
<FooterTemplate> |
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> |
<ContentTemplate> |
<table style="border-bottom: 1px dotted #EFEFEF; margin-bottom: 1px; font-size: 11px;" width="98%"> |
<tr> |
<td> |
<asp:Label ID="DateRangeLabel" runat="server"><b>Custom:</b></asp:Label> |
</td> |
</tr> |
<tr> |
<td> |
<asp:Label ID="DateRangeFromLabel" runat="server" AssociatedControlID="fromDatePicker"> From: </asp:Label> |
<telerik:RadDatePicker ID="fromDatePicker" runat="server" |
Width="120px" |
BackColor="White" |
BorderWidth="0" |
AutoPostBack="false" |
ZIndex="8000" |
DateInput-EmptyMessage="MM/DD/YYYY" |
OnSelectedDateChanged="RadDatePicker_OnSelectedDateChanged"> |
<ClientEvents OnDateSelected="FromDateSelected" /> |
</telerik:RadDatePicker> |
<asp:Label ID="DateRangeToLabel" runat="server" AssociatedControlID="toDatePicker"> To: </asp:Label> |
<telerik:RadDatePicker ID="toDatePicker" runat="server" |
Width="120px" |
BackColor="White" |
BorderWidth="0" |
ZIndex="8000" |
AutoPostBack="true" |
DateInput-EmptyMessage="MM/DD/YYYY" |
Enabled="false" |
OnSelectedDateChanged="RadDatePicker_OnSelectedDateChanged"> |
<ClientEvents OnDateSelected="ToDateSelected" /> |
</telerik:RadDatePicker> |
</td> |
</tr> |
</table> |
</ContentTemplate> |
</asp:UpdatePanel> |
</FooterTemplate> |
</telerik:RadComboBox> |