This is a migrated thread and some comments may be shown as answers.

InPlace Edit and Focus

5 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Velma
Top achievements
Rank 1
Velma asked on 22 Aug 2011, 10:31 PM
How could I set the focus to this field when the grid goes into InPlace edit mode? I tried
catching it in the ItemCreated event per some samples for EditForms, but I couldn't catch
it. Nothing I tried worked...

<
telerik:GridTemplateColumn
      HeaderText="Awarded"
      SortExpression="Awarded" UniqueName="Awarded" ForceExtractValue="Always"
<ItemTemplate
   <asp:Label runat="server" ID="Awarded" Text='<%# Eval("Awarded", "{0:N0}")%>'></asp:Label>
 </ItemTemplate
 <EditItemTemplate>
   <telerik:RadNumericTextBox ID="AwardedTextBox" runat="server" MaxLength="7" MaxValue="999999" MinValue="0000" Width="90px"
      NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator="," Text='<%# Bind("Awarded") %>' />
 </EditItemTemplate>
 <HeaderStyle Width="90px" HorizontalAlign="Center" />
 <ItemStyle HorizontalAlign="Right" />
</
telerik:GridTemplateColumn>

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Aug 2011, 05:43 AM
Hello Velma,

Try the following code snippet in ItemDataBound event.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridEditableItem && e.Item.IsInEditMode)
  {
      GridEditableItem item = (GridEditableItem)e.Item;
      RadNumericTextBox txt = (RadNumericTextBox)item.FindControl("AwardedTextBox");
      txt.Focus();
  }
}

Thanks,
Princy.
0
Velma
Top achievements
Rank 1
answered on 26 Aug 2011, 03:34 PM
Thank you. Worked great. Cut and paste.
0
Fred
Top achievements
Rank 1
answered on 22 Feb 2012, 10:57 PM

I tried this code but it did not work for me. I think the difference is I am using a webusercontrol in a modal window

<EditFormSettings UserControlName="editform.ascx" EditFormType="WebUserControl" PopUpSettings-Modal="true">

</EditFormSettings>

and then creating the form dynamically. I tried setting the focus in the editform.apx even though it could find the control and I didn't get errors using the focus() the focus was not set. Curious that telerik doesn't automatically set the focus to the first input control. Or is there something I could not find.

Thanks

0
Princy
Top achievements
Rank 2
answered on 23 Feb 2012, 05:41 AM
Hello,

Try the following code.
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
 {
   if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
       GridEditFormItem item = (GridEditFormItem)e.Item;
       UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
       TextBox txt = (TextBox)userControl.FindControl("TextBox1");
       txt.Focus();
    }
 }

Thanks,
Princy.
0
Fred
Top achievements
Rank 1
answered on 23 Feb 2012, 02:58 PM
it found the control ok, set the focus or at least did not report an error but when the editform popped up the focus was not set on the textbox. as a matter of fact, just as in the past, it was not focused anywhere as far as I could see. attached is a screen shot
Tags
Grid
Asked by
Velma
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Velma
Top achievements
Rank 1
Fred
Top achievements
Rank 1
Share this question
or