I have a statically declared Grid as follows:
I create columns and bind data to this grid dynamically on the results of a search.
When the results are bound to the grid I use the down arrow key to navigate to the record of interest and press enter. Normally on a grid where the columns are declared in the aspx file the
For some reason the Sort event is getting fired also when the enter key is pressed, the command argument the first time through the ItemCommand event is "Edit" as is expected and the next time through ItemCommand it is "Sort" after whihc the ItemSorted event is fired also.
I tried setting allowsorting to false and taking out the sorting command handler, and the behaviour gets a little wierder in that the Export to Excel button that is outside the grid is fired in addition to the ItemCommand of the Grid. Also in this scenario the grid does not recieve focus as specified, so I have to manually click the grid with the mouse before I can navigate with the keyoard. Could you provide some insight as to the problem? Thanks
Jonathan
<telerik:RadPageView ID="PageView4" runat="server" Width="100%" > |
<table width="100%" cellpadding="5"> |
<tr><td> |
<asp:Button ID="btnExport" runat="server" Text="Export Results to Excel" OnClick="btnExport_Click" /> |
</td></tr> |
<tr> |
<td> |
<telerik:RadGrid |
ID="radgridResources" |
runat="server" |
AllowPaging="True" |
Width="100%" |
enableEmbeddedSkins="false" |
Skin="FaCTS" |
pagesize="15" |
AllowSorting="true" |
OnPageIndexChanged="radgridResources_PageIndexChanged" |
OnItemCommand="radgridResources_ItemCommand" |
OnSortCommand="radgridResources_SortCommand" |
ClientSettings-AllowKeyboardNavigation="true" |
EnableNoRecordsTemplate="true" |
ItemStyle-HorizontalAlign="Center" |
AlternatingItemStyle-HorizontalAlign="Center" |
HeaderStyle-HorizontalAlign="Center"> |
<PagerStyle Mode="NextPrevAndNumeric" /> |
<MasterTableView |
AutoGenerateColumns="False" |
DataKeyNames="ID" |
Width="100%" |
CommandItemDisplay="None" |
PageSize="15"> |
<Columns> |
</Columns> |
<EditFormSettings> |
<PopUpSettings ScrollBars="None" /> |
</EditFormSettings> |
<NoRecordsTemplate> |
<div align="center" style="color:darkorange">---------- No Records to Display -----------</div> |
</NoRecordsTemplate> |
</MasterTableView> |
<ClientSettings> |
</ClientSettings> |
</telerik:RadGrid></td></tr></table></telerik:RadPageView> |
I create columns and bind data to this grid dynamically on the results of a search.
protected void LoadResources(bool resetPage) |
{ |
//basic or advanced? |
if (Session["ResourceSearchType"] == "basic") |
{ |
_resources = ResourceService.GetSimpleSearchResults(txtName.Text, Int32.Parse(ddlServiceCategory1.SelectedValue), Int32.Parse(ddlServiceCategory2.SelectedValue), Int32.Parse(ddlServiceCategory3.SelectedValue), Int32.Parse(ddlCityProx.SelectedValue), txtZipCode.Text, txtAddress.Text, Int32.Parse(ddlCityExact.SelectedValue), txtZipCodeExact.Text, Int32.Parse(ddlLanguage.SelectedValue), Int32.Parse(ddlCity1.SelectedValue), Int32.Parse(ddlCity2.SelectedValue), Int32.Parse(ddlCity3.SelectedValue), txtDescription.Text); |
} |
else if ((Session["ResourceSearchType"] == "advanced") && (!(txtSqlWhere.Text == string.Empty))) |
{ |
//load the advanced search resources |
_resources = ResourceService.GetAdvancedSearchResults(txtSqlWhere.Text); |
} |
//see if we're using the selected columns |
if (((rdoBasicUseSelectedColumns.Checked == true) && (Session["ResourceSearchType"] == "basic")) || |
((rdoAdvancedUseSelectedColumns.Checked == true) && (Session["ResourceSearchType"] == "advanced"))) |
{ |
... |
} |
else |
{ |
//Use the default columns |
///todo: |
///load the default columns from the database for a search |
radgridResources.MasterTableView.Columns.Clear(); |
GridButtonColumn _buttonColumn; |
GridBoundColumn _boundColumn; |
GridHyperLinkColumn _hyperLinkColumn; |
_buttonColumn = new GridButtonColumn(); |
radgridResources.MasterTableView.Columns.Add(_buttonColumn); |
_buttonColumn.ButtonType = Telerik.Web.UI.GridButtonColumnType.LinkButton; |
_buttonColumn.DataTextField = "Name"; |
_buttonColumn.HeaderText = "Name"; |
_buttonColumn.CommandName = "Edit"; |
_buttonColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center; |
_buttonColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center; |
_buttonColumn.SortExpression = "Name"; |
_buttonColumn.HeaderStyle.Width = 150; |
_boundColumn = new GridBoundColumn(); |
radgridResources.MasterTableView.Columns.Add(_boundColumn); |
_boundColumn.DataField = "Phone1Description"; |
_boundColumn.HeaderText = "Phone 1"; |
_buttonColumn.SortExpression = "Phone1Description"; |
_boundColumn.HeaderStyle.Width = 100; |
_boundColumn = new GridBoundColumn(); |
radgridResources.MasterTableView.Columns.Add(_boundColumn); |
_boundColumn.DataField = "Phone2Description"; |
_boundColumn.HeaderText = "Phone 2"; |
_buttonColumn.SortExpression = "Phone2Description"; |
_boundColumn.HeaderStyle.Width = 100; |
_boundColumn = new GridBoundColumn(); |
radgridResources.MasterTableView.Columns.Add(_boundColumn); |
_boundColumn.DataField = "Phone1Description"; |
_boundColumn.HeaderText = "Phone 3"; |
_buttonColumn.SortExpression = "Phone3Description"; |
_boundColumn.HeaderStyle.Width = 100; |
_boundColumn = new GridBoundColumn(); |
radgridResources.MasterTableView.Columns.Add(_boundColumn); |
_boundColumn.DataField = "DescriptionSummary"; |
_boundColumn.HeaderText = "DescriptionSummary"; |
_hyperLinkColumn = new GridHyperLinkColumn(); |
radgridResources.MasterTableView.Columns.Add(_hyperLinkColumn); |
_hyperLinkColumn.DataTextField = "WebSiteURL"; |
string[] fields = { "WebSiteURL" }; |
_hyperLinkColumn.DataNavigateUrlFields = fields; |
_hyperLinkColumn.DataNavigateUrlFormatString = "{0}"; |
_hyperLinkColumn.HeaderStyle.Width = 150; |
_hyperLinkColumn.HeaderText = "Web Site"; |
_hyperLinkColumn.Target = "_blank"; |
_boundColumn = new GridBoundColumn(); |
radgridResources.MasterTableView.Columns.Add(_boundColumn); |
_boundColumn.DataField = "MinimumDistance"; |
_boundColumn.HeaderText = "Min Distance"; |
_boundColumn.SortExpression = "MinimumDistance"; |
_boundColumn.HeaderStyle.Width = 80; |
if (((UserProfile)Session["_userProfile"]).IsAuthorized("Resource - Delete")) |
{ |
_buttonColumn = new GridButtonColumn(); |
radgridResources.MasterTableView.Columns.Add(_buttonColumn); |
_buttonColumn.ButtonType = GridButtonColumnType.ImageButton; |
_buttonColumn.ConfirmDialogType = GridConfirmDialogType.Classic; |
_buttonColumn.ConfirmText = "Delete this resource?"; |
_buttonColumn.HeaderText = "Delete"; |
_buttonColumn.HeaderStyle.Width = 60; |
_buttonColumn.CommandName = "Delete"; |
_buttonColumn.ImageUrl = "./images/delete.gif"; |
} |
} |
radgridResources.MasterTableView.TableLayout = GridTableLayout.Fixed; |
radgridResources.DataSource = _resources; |
if (resetPage == true) |
{ |
radgridResources.CurrentPageIndex = 0; |
} |
radgridResources.DataBind(); |
radgridResources.Focus(); |
} |
When the results are bound to the grid I use the down arrow key to navigate to the record of interest and press enter. Normally on a grid where the columns are declared in the aspx file the
radgridResources_ItemCommand
event handler is fired once and I navigate to a page based on the Id of the row.For some reason the Sort event is getting fired also when the enter key is pressed, the command argument the first time through the ItemCommand event is "Edit" as is expected and the next time through ItemCommand it is "Sort" after whihc the ItemSorted event is fired also.
I tried setting allowsorting to false and taking out the sorting command handler, and the behaviour gets a little wierder in that the Export to Excel button that is outside the grid is fired in addition to the ItemCommand of the Grid. Also in this scenario the grid does not recieve focus as specified, so I have to manually click the grid with the mouse before I can navigate with the keyoard. Could you provide some insight as to the problem? Thanks
Jonathan