or
I'm trying to use a raddatepicker in a radgrid where the user can only select the Month and Year, rather than the date from the RadCalendar.
| <script type="text/javascript"> |
| //override the onload event handler to change the picker after the page is loaded |
| window.onload = function () |
| { |
| window.setTimeout(function() {SetCalendarTable();},200) |
| } |
| function SetCalendarTable() |
| { |
| var picker = "ctl00_RadPanel_ForecastGrid_ctl00_ctl02_ctl02_rdpForecastStartDate"; |
| var calendar = picker.get_calendar(); |
| var fastNavigation = calendar._getFastNavigation(); |
| $clearHandlers(picker.get_popupButton()); |
| $addHandler(picker.get_popupButton(), "click", function() |
| { |
| //debugger; |
| var textbox = picker.get_textBox(); |
| //adjust where to show the popup table |
| var x, y; |
| var adjustElement = textbox; |
| if (textbox.style.display == "none") |
| adjustElement = picker.get_popupImage(); |
| var pos = picker.getElementPosition(adjustElement); |
| x = pos.x; |
| y = pos.y + adjustElement.offsetHeight; |
| var e = { |
| clientX : x, |
| clientY : y |
| }; |
| //synchronize the input date if set with the picker one |
| var date = picker.get_selectedDate(); |
| if(date) |
| { |
| calendar.FocusedDate[0] = date.getFullYear(); |
| calendar.FocusedDate[1] = date.getMonth() + 1; |
| } |
| $get(calendar._titleID).onclick(e); |
| }); |
| fastNavigation.OnOK = |
| function() |
| { |
| var date = new Date(fastNavigation.Year, fastNavigation.Month, 1); |
| picker.get_dateInput().SetDate(date); |
| fastNavigation.Popup.Hide(); |
| } |
| fastNavigation.OnToday = |
| function() |
| { |
| var date = new Date(); |
| picker.get_dateInput().SetDate(date); |
| fastNavigation.Popup.Hide(); |
| } |
| } |
| </script> |
| <telerik:RadGrid ID="ForecastGrid" |
| AllowPaging="True" |
| AllowSorting="True" |
| EnableEmbeddedSkins="false" |
| GridLines="None" |
| OnInsertCommand="ForecastGrid_InsertCommand" |
| OnItemCommand="ForecastGrid_ItemCommand" |
| OnItemCreated="ForecastGrid_ItemCreated" |
| OnItemDataBound="ForecastGrid_ItemDataBound" |
| OnNeedDataSource="ForecastGrid_NeedDataSource" |
| OnUpdateCommand="ForecastGrid_UpdateCommand" |
| PageSize="15" |
| runat="server" |
| ShowFooter = "true" |
| Skin="AO" |
| Visible = "true"> |
| <MasterTableView CommandItemDisplay="Bottom" AutoGenerateColumns = "false" DataKeyNames="ForecastId"> |
| <EditFormSettings EditFormType = "Template"> |
| <FormTemplate> |
| <div style="padding: 10px;"> |
| <div class="text"> |
| Click the <b>Save</b> button to save your changes.</div> |
| <div> |
| <asp:Label Visible="false" ID="ErrorLabel" runat="server" /></div> |
| <div style="clear: both;"> |
| </div> |
| <div class="validation-summary"> |
| <asp:ValidationSummary HeaderText="Changes not saved." DisplayMode="SingleParagraph" |
| ID="ValidationSummary1" runat="server"></asp:ValidationSummary> |
| </div> |
| <div style="clear: both;"> |
| </div> |
| <div> |
| <asp:Label ID="ForecastIdLabel" Visible="false" runat="server" Text='<%# Bind("ForecastId") %>'></asp:Label></div> |
| <div> |
| <div> |
| <asp:Label ID="IsActiveLabel" Visible="false" runat="server" Text='<%# Bind("IsActive") %>'></asp:Label> |
| </div> |
| <div class="label-short" style="float: left; padding-bottom: 5px; width:150px;"> |
| Forecast Name:</div> |
| <div style="padding-bottom: 5px;"> |
| <Telerik:RadTextBox ID="ForecastName" runat="server" Skin="AO" EnableEmbeddedSkins="false" |
| Text='<%# Bind("ForecastName") %>' Width="240" MaxLength="50"> |
| </Telerik:RadTextBox> |
| <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ForecastName" |
| ErrorMessage="Forecast Name is required.">*</asp:RequiredFieldValidator> |
| </div> |
| <div style="clear: both;"> |
| </div> |
| <div class="label-short" style="float: left; padding-bottom: 5px; width:150px;"> |
| Forecast Start Date:</div> |
| <div style="padding-bottom: 5px;"> |
| <telerik:RadDatePicker ID="rdpForecastStartDate" DateInput-DateFormat="MMMM, yyyy" runat="server" |
| AutoPostBack="false" ToolTip="Month" Width="130px" CssClass="date-picker" Skin="AO" |
| EnableEmbeddedSkins="false"> |
| </telerik:RadDatePicker> |
| <%--<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="rdpForecastStartDate" |
| ErrorMessage="Forecast Start Date is required.">*</asp:RequiredFieldValidator>--%> |
| </div> |
| <div style="clear: both;"> |
| </div> |
| <div class="label-short" style="float: left; padding-bottom: 5px; width:150px;"> |
| Forecast Length:</div> |
| <div style="padding-bottom: 5px;"> |
| <telerik:RadComboBox ID="rcbForecastLength" runat="server" ZIndex="7020" Skin="AO" EnableEmbeddedSkins="false" Width="243"> |
| </telerik:RadComboBox> |
| <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="rcbForecastLength" |
| ErrorMessage="Forecast Length is required.">*</asp:RequiredFieldValidator> |
| </div> |
| <div style="clear: both;"> |
| </div> |
| <div class="label-short" style="float: left; padding-bottom: 5px; width:150px;"> |
| Is Active:</div> |
| <div style="float: left; padding-bottom: 5px;"> |
| <asp:CheckBox ID="IsActiveCheckbox" runat="server"></asp:CheckBox> |
| </div> |
| <div style="clear: both;"> |
| </div> |
| <div> |
| <asp:Button ID="UpdateButton" CssClass="button" runat="server" Text="Save" CommandName="Update" /> |
| <asp:Button ID="InsertButton" CssClass="button" runat="server" Text="Save" CommandName="PerformInsert" /> |
| <asp:Button ID="CancelButton" CssClass="button" runat="server" Text="Cancel" CommandName="Cancel" |
| CausesValidation="false" /> |
| </div> |
| </div> |
| </FormTemplate> |
| </EditFormSettings> |
| </MasterTableView> |
| </telerik:RadGrid> |
using System;using Telerik.Web.UI;public partial class Default : System.Web.UI.Page { public class A { public int a { get; set; } public int b { get; set; } } protected void Page_Load(object sender, EventArgs e) { RadGrid1.DataSource = new A[] {new A() {a = 1, b = 2}, new A() {a = 3, b = 4}}; } protected void rg_ItemCommand(object sender, GridCommandEventArgs e) { int i = e.Item.ItemIndex; GridDataItem item = (GridDataItem)e.Item; int letterId = (int)item.GetDataKeyValue("a"); //GridDataItem dataItem = RadGrid1.SelectedItems[0] as GridDataItem; }}<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" /></head><body> <form id="form1" runat="server"> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> <Scripts> <asp:ScriptReference Assembly="Telerik.Web.UI, Version=2012.3.1205.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Name="Telerik.Web.UI.Common.Core.js" /> <asp:ScriptReference Assembly="Telerik.Web.UI, Version=2012.3.1205.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Name="Telerik.Web.UI.Common.jQuery.js" /> <asp:ScriptReference Assembly="Telerik.Web.UI, Version=2012.3.1205.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Name="Telerik.Web.UI.Common.jQueryInclude.js" /> </Scripts> </telerik:RadScriptManager> <script type="text/javascript"> //Put your JavaScript code here. </script> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> </telerik:RadAjaxManager> <div> <telerik:RadGrid ID="RadGrid1" runat="server" OnItemCommand="rg_ItemCommand"> <MasterTableView DataKeyNames="a" AutoGenerateColumns="False"> <Columns> <telerik:GridBoundColumn DataField="a" DataType="System.Int32"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="b" DataType="System.Int32"> </telerik:GridBoundColumn> <telerik:GridButtonColumn ButtonType="LinkButton" CommandName="test" Text="test"> </telerik:GridButtonColumn> </Columns> </MasterTableView> <ClientSettings> <%--removing Oncommand will make itemindex work--%> <ClientEvents OnCommand="rgCommand" /> </ClientSettings> </telerik:RadGrid> </div> <script type="text/javascript"> function rgCommand(sender, args) { var commandName = args.get_commandName(); } </script> </form></body></html>((Wcsr.ProjectBilling.Business.Data.ProjectTask) (Container.DataItem ?? new Wcsr.ProjectBilling.Business.Data.ProjectTask())).Code<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" DefaultMode="Edit" OnItemUpdated="FormView1_ItemUpdated" OnItemUpdating="FormView1_ItemUpdating"> <EditItemTemplate> <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Metro" Width="100%"> <Items> <telerik:RadPanelItem runat="server" Expanded="True" PreventCollapse="True" Text="Basic Task Information"> <ContentTemplate> <div> <asp:Label ID="Label1" runat="server" CssClass="fieldLabel">Task Code</asp:Label> <%-- For some reason RadPanelItem requires you to do databinding with DataBinder.Eval --%> <asp:TextBox ID="TaskCodeTb" runat="server" MaxLength="20" Text='<%# ((Wcsr.ProjectBilling.Business.Data.ProjectTask) (Container.DataItem ?? new Wcsr.ProjectBilling.Business.Data.ProjectTask())).Code %>'></asp:TextBox> </div> <div> <asp:Label ID="Label4" runat="server" CssClass="fieldLabel">Task Description</asp:Label> <asp:TextBox ID="DescriptionTb" runat="server" MaxLength="250" Rows="3" Text='<%# ((Wcsr.ProjectBilling.Business.Data.ProjectTask) (Container.DataItem ?? new Wcsr.ProjectBilling.Business.Data.ProjectTask())).Description %>' TextMode="MultiLine"></asp:TextBox> </div> </ContentTemplate> </telerik:RadPanelItem> </telerik:RadPanelBar> <asp:LinkButton runat="server" ID="UpdateLb" Text="Update" CommandName="Update"></asp:LinkButton> <asp:LinkButton runat="server" ID="CancelLb" Text="Cancel" CommandName="Cancel"></asp:LinkButton> </EditItemTemplate> </asp:FormView>