A bit more involved than the title indicates, though. We've developed a search control (mark-up and some code below) which uses a RadAjaxPanel to set dates. When the date changes, as part of the ajax postback, we go look up valid data for that date range and populate other search criteria.
All that's working great; the request I got was to handle the enter key being pressed and submit a search. Of course, I'll want to apply it to whatever control has focus when an enter key is hit, but the textboxes in the date picker controls seems like an obvious place to start.
I've tried following this thread, but I'm not really getting it. I'm not sure what event I should hook into to notice an enter key. It doesn't seem like any client-side event is exposed which has to do with the text box of the date picker.
The script I've cobbled together is invoked by a change when you use the actual date-picking UI part of the date picker control, so that's not quite what I'm looking for. An error is raised saying that the object doesn't support this property or method, presumably when I'm trying to attach the event handler (I see the alert just before it).
Maybe I'm taking a completely wrong approach. I'm pretty lost on the direction to go, and need a push.
Control mark-up:
---------------------------
<%@ Control Language="C#" AutoEventWireup="false"
CodeBehind="SearchFilterUI.ascx.cs"
Inherits="Com.Wolfgang.Amadeus.gTime.Web.SearchFilterUI" %>
<%@ Register TagPrefix="radC" Namespace="Telerik.WebControls"
Assembly="RadCalendar.Net2" %>
<%@ Register TagPrefix="radCB" Namespace="Telerik.WebControls"
Assembly="RadComboBox.Net2" %>
<%@ Register TagPrefix="radA" Namespace="Telerik.WebControls"
Assembly="RadAjax.Net2" %>
<div>
<radA:RadAjaxPanel ID="radAjaxPanel" runat="server" LoadingPanelID="ajaxLoadingPanel">
<div id="divSearchPeriod" runat="server" style="float: left;">
<asp:Label ID="lblByPayPeriod" runat="server" Font-Bold="true" Font-Size="Medium"
Text="Search by Pay Period:"></asp:Label>
<br />
<asp:Label ID="lblPayPeriod" runat="server" Text="Pay Period:" Width="75 px"></asp:Label>
<radCB:RadComboBox ID="rcbPayPeriod" runat="server" AutoPostBack="true" MarkFirstMatch="true"
OnSelectedIndexChanged="rcbPayPeriod_SelectedIndexChanged">
</radCB:RadComboBox>
<br />
<asp:Label ID="lblYear" runat="server" Text="Year:" Width="75 px"></asp:Label>
<radCB:RadComboBox ID="rcbYear" runat="server" AutoPostBack="true" MarkFirstMatch="true"
OnSelectedIndexChanged="rcbYear_SelectedIndexChanged">
</radCB:RadComboBox>
</div>
<div style="float: left; width: 343px;">
<asp:Label ID="lblByDates" runat="server" Font-Bold="true" Font-Size="Medium" Text="Search by Dates:"></asp:Label>
<br />
<asp:Label ID="lblStart" runat="server" Text="Start Date:" Width="70 px"></asp:Label>
<radC:RadDatePicker ID="rcStart" runat="server" AutoPostBack="true" EnableMultiSelect="false"
OnSelectedDateChanged="rcStart_SelectionChanged" ClientEvents-OnDateSelected="HandleEnter">
</radC:RadDatePicker>
<br />
<div style="float: right;">
</div>
<asp:Label ID="lblEnd" runat="server" Width="70 px" Text="End Date:"></asp:Label>
<radC:RadDatePicker ID="rcEnd" runat="server" AutoPostBack="true" EnableMultiSelect="false"
OnSelectedDateChanged="rcEnd_SelectionChanged">
</radC:RadDatePicker>
</div>
<div>
<br />
<br />
<br />
<br />
<br />
<asp:Panel ID="pnlUser" runat="server">
<asp:Label ID="lblUserName" runat="server" Text="User Name:" Width="110px"></asp:Label>
<radCB:RadComboBox ID="rcUser" runat="server" MarkFirstMatch="true">
</radCB:RadComboBox>
<asp:Label ID="lblNoUsers" runat="server" Text="No User Records in Selected Criteria"
Visible="false" />
</asp:Panel>
<asp:Panel ID="pnlClient" runat="server">
<asp:Label ID="lblClientName" runat="server" Text="Client Name:" Width="110px"></asp:Label>
<radCB:RadComboBox ID="rcClient" runat="server" MarkFirstMatch="true">
</radCB:RadComboBox>
<asp:Label ID="lblNoClients" runat="server" Text="No Client Records in Selected Criteria"
Visible="false" />
</asp:Panel>
<asp:Panel ID="pnlProject" runat="server">
<asp:Label ID="lblProjectName" runat="server" Text="Project Name:" Width="110px"></asp:Label>
<radCB:RadComboBox ID="rcProject" runat="server" MarkFirstMatch="true">
</radCB:RadComboBox>
<asp:Label ID="lblNoProjects" runat="server" Text="No Project Records in Selected Criteria"
Visible="false" />
</asp:Panel>
<asp:Panel ID="pnlUserRole" runat="server">
<asp:Label ID="lblUserRole" runat="server" Text="User Role:" Width="110px" />
<radCB:RadComboBox ID="rcUserRole" runat="server" MarkFirstMatch="true" />
</asp:Panel>
</div>
</radA:RadAjaxPanel>
<radA:AjaxLoadingPanel ID="ajaxLoadingPanel" runat="server" Transparency="25" BackColor="window">
<asp:Image ID="imgLoading" runat="server" ImageUrl="~/Loading.gif" AlternateText="Loading..." />
</radA:AjaxLoadingPanel>
</div>
<div>
<br />
<asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search" />
</div>
<hr />
<div>
<asp:Label ID="lblSearchValue" runat="server"></asp:Label>
</div>
------------------------------
Here's how I tried to set up the javascript. This is in the PreRender event handler of the search control: (I figured once I got used to the setup, I could figure out how to actually invoke the btnSubmit's Submit then).
StringBuilder
js = new StringBuilder();
js.Append(
"<script type=\"text/javascript\">");
js.Append(
"\n");
js.Append(
"function HandleEnter(datePicker) {");
js.Append(
"\n\t");
js.Append(
"alert(\"here we are\");");
js.Append(
"\n\t");
js.Append(
"datePicker.AttachEventHandler(\"onkeydown\", function(eventArgs) {");
js.Append(
"\n\t\t");
js.Append(
"var key= eventArgs.keyCode;");
js.Append(
"\n\t\t");
js.Append(
"alert(\"key hit was: \" + key);");
js.Append(
"\n\t");
js.Append(
"}");
js.Append(
"\n\t");
js.Append(
");");
js.Append(
"\n\t");
js.Append(
"return false;");
js.Append(
"\n");
js.Append(
"}");
js.Append(
"\n");
js.Append(
"</script>");
this.Page.RegisterClientScriptBlock("keypress", js.ToString());

<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Test.aspx.vb" Inherits="ProjectTemplar.Test"
title="Untitled Page" EnableViewState="true"%>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<asp:Label ID="lblErrorMsg" runat="server" CssClass="errorFont"></asp:Label>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
OnNeedDataSource="RadGrid1_NeedDataSource"
OnUpdateCommand="RadGrid1_UpdateCommand">
<MasterTableView EditMode="InPlace">
<Columns>
<telerik:GridEditCommandColumn UpdateText="Update" EditText="Edit" CancelText="Cancel"></telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="BudgetExceptionID" Visible="TRUE" HEADERTEXT = "BudgetExceptionID" UniqueName="BudgetExceptionID" readonly="true"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ExceptionNotes" HeaderText="Exp. Notes" UniqueName="ExceptionNotes" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Budget_DATETIME" HeaderText="Date & Time">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="EffectivePeriod" HeaderText="Effective Period"
UniqueName="EffectivePeriod">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</asp:Content>
--Code Behind ---
Imports Telerik.Web.UI
Partial Public Class Test
Inherits System.Web.UI.Page
Private ReadOnly Property GridSource() As DataTable
Get
Dim obj As Object = Me.ViewState("_gds")
If (Not obj Is Nothing) Then
Return CType(obj, DataTable)
Else
Dim table As DataTable = Nothing
Try
Dim ds As DataSet
Dim batchManager As New DataBatchManager()
ds = batchManager.GetBudgetExceptionsByBatchID(34)
table = ds.Tables(0)
Me.ViewState("_gds") = table
Return table
Catch ex As Exception
lblErrorMsg.Text = ex.Message
End Try
Return table
End If
End Get
End Property
Protected Sub RadGrid1_NeedDataSource(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
RadGrid1.DataSource = Me.GridSource
End Sub
Protected Sub RadGrid1_UpdateCommand(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim ordersTable As DataTable = Me.GridSource
Dim id As String
id = editedItem("Client").Text '...returns blank..
lblErrorMsg.Text = "Hello " + id.ToString()
End Sub
<
telerik:RadGrid ID="personalGridView" runat="server" AutoGenerateColumns="False"
AllowPaging="True" GridLines="None" AllowMultiRowSelection="true" ShowGroupPanel="False"
Skin="Office2007" OnPreRender="personalGridView_PreRender" OnPageIndexChanged="personalGridView_PageIndexChanged">
<FilterMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
<PagerStyle Mode="NumericPages" />
<MasterTableView>
<GroupByExpressions>
<telerik:GridGroupByExpression>
<SelectFields>
<telerik:GridGroupByField FieldAlias="Name" FieldName="Name" FormatString="" HeaderText="" />
</SelectFields>
<GroupByFields>
<telerik:GridGroupByField FieldName="Name" FieldAlias="Name" FormatString="" HeaderText="" />
</GroupByFields>
</telerik:GridGroupByExpression>
</GroupByExpressions>
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridClientSelectColumn CommandName="Select">
</telerik:GridClientSelectColumn>
<
telerik:GridBoundColumn DataField="Amount" HeaderText="Amount">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowDragToGroup="False">
<Selecting AllowRowSelect="True"></Selecting>
<Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
<ClientMessages DragToGroupOrReorder="Drag to group" />
</ClientSettings>
</telerik:RadGrid>
foreach
(GridItem grdItem in personalGridView.SelectedItems)
{
}
protected
void Order_InsertCommand(object source, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
Hashtable newValues = new Hashtable();
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
// get the selected customerID from the first grid...
}
Thank you in advance
GridDropDownColumn in my codebehind (c#), ive found examples where the datasourceid is set in the aspx page like this
| <telerik:GridDropDownColumn |
| UniqueName="DropDownListCategory" |
| ListTextField="Category" |
| ListValueField="Category" |
| DataSourceID="SqlDataSource2" |
| HeaderText="Category" |
| DataField="Category" |
| DropDownControlType="RadComboBox" |
| AllowSorting="true"> |
| </telerik:GridDropDownColumn> |