I’ve been trying to set focus on a DropdownList input cell in a Popup edit form. I tried putting code on the ItemDataBound event without much luck.
I was wondering if using the “Grid / PopUp Edit Form” http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/popupeditform/defaultcs.aspx example someone could show me how to set focus on the “Title Of Courtesy” dropdown field when in edit mode. At the very least I’d like to see how to set focus on the Popup Edit form itself. Thanks.
6 Answers, 1 is accepted
I would suggest you to try the following approach:
protected
void
MyGrid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItem form = (GridEditFormItem)e.Item;
DropDownList list = form.FindControl(
"MyDropDownID"
)
as
DropDownList;
list.Focus();
}
}
You can also check this help article:
Focus the text boxes in the edit control
I hope this helps,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I tried both solutions ( "attach to the ItemDataBound event handler" and "adds a literal control to Telerik RadGrid, containing JavaScript code" ) in the link http://www.telerik.com/help/aspnet-ajax/grdsetfocusontextboxesineditcontrol.html and neither one sets focus on the POPUP edit control. I'm using the baked in auto edit form (not a template).
I also found a discussion in thread http://www.telerik.com/community/forums/aspnet-ajax/grid/popup-edit-form-setting-focus-error.aspx and the last response shows using a template. I tried this template and it worked but of course I only ended up with the single numeric text box.
Will focus work with the automatically generated edit Popup form?
I don't want to manually create my popup edit control in a FormTemplate section of my aspx file. Right now all my fields are databound and inserts and updates are working fine.
<FormTemplate> |
||||||||||
<telerik:RadNumericTextBox ID="TextBox1" Value="1" runat="server" /> |
||||||||||
</FormTemplate>
|
I was able to get it to work by changing the EditMode="Editforms" instead of "Popup" in the aspx file. In the aspx.cs file I added the following code to the ItemCreated event.
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItem item = (GridEditFormItem)e.Item;
DropDownList list = (item as GridEditableItem)["PartTypeDropDown"].Controls[0] as DropDownList;
list.Focus();
}
Still would like to know how to get this to work with EditMode="Popup". Thanks
I have created a small sample project demonstrating how to achieve the desired functionality. Give it a try and let me know how it goes on your side.
I hope this helps,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
"htmlfile: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."
Also, a difference between the solution file and my code is that I am using a FormTemplate for the EditForm.
I have attached a modified version of the sample project that runs as expected on my side. Please give it a try and let me know how it goes.
Regards,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.