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

How to findcontrol in EditCommand event.

4 Answers 667 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Durga
Top achievements
Rank 1
Durga asked on 29 Jul 2008, 06:55 PM

Hello,

I have a requirement like this,

I have a radGrid with a 2 columns.

Column 1 is a template column with
ItemTemplate as  asp:Linkbutton CommandName="Edit"and
EditItemTemplate as RadTextBox
<asp:ImageButton ID="btnQUpdate" CommandName="Update"
<asp:ImageButton ID="btnQCancel" CommandName="Cancel"

Column 2 is GridTemplateColumn with CommandName="Delete"

On click of the Linkbutton column row text, the grid row is setting in to edit mode and textbox is appearing with update and cancel buttons.
What I need here is,
1. I need to set the focus in that text box and select the current text in that box. so that user will be ready to update the text. ( so that setting focus and highlighting text events can be avoided)
2. On press Enter on that textbox the "Update" button click event should invoke.

I am really glad if some body help me to achieve this functionality

Thanks,
Durga

 

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Jul 2008, 08:00 AM
Hello Durga,

You can try out the following code to set the focus on the RadTextBox and select the text in the TextBox on focus.

aspx:
 <telerik:GridTemplateColumn UniqueName="TemplateColumn"
        <ItemTemplate> 
            <asp:LinkButton ID="LinkButton1" CommandName="Edit" runat="server" >Edit</asp:LinkButton> 
        </ItemTemplate> 
        <EditItemTemplate> 
            <telerik:RadTextBox ID="RadTextBox1" Text='<%#Bind("FirstName")%>'  runat="server"
            </telerik:RadTextBox> 
            <asp:Button ID="Button1" runat="server" CommandName="Update" Text="Update"/> 
            <asp:Button ID="Button2" runat="server" CommandName="Cancel" Text="Cancel"/> 
        </EditItemTemplate> 
        </telerik:GridTemplateColumn> 

cs:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem item = (GridEditableItem)e.Item; 
            RadTextBox txtbx = (RadTextBox)item["TemplateColumn"].FindControl("RadTextBox1"); 
            txtbx.Focus(); 
            txtbx.SelectionOnFocus = SelectionOnFocus.SelectAll;            
        } 
    } 

Thanks
Princy.
0
Mayank
Top achievements
Rank 1
answered on 15 Jan 2014, 07:49 AM
how to find control on
  protected void RadGrid2_EditCommand(object sender, GridCommandEventArgs e)
        {
//find EditItemTemplate control
}
0
Princy
Top achievements
Rank 2
answered on 15 Jan 2014, 12:10 PM
Hi Mayank,

You cannot access the Edit controls in the OnEditCommand event since the EditCommand is too early to access the edit form items, you can access the items in the ItemDataBound event of the grid instead as follows:

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem edit = (GridEditableItem)e.Item;
        TextBox txt = (TextBox)edit.FindControl("TextBox1"); //Access the EditItemTemplate control
        string value = txt.Text;
    }
}

Thanks,
Princy
0
Mayank
Top achievements
Rank 1
answered on 07 Mar 2014, 10:53 AM
Thanks thanks thanks ..it's working...:)
Tags
Grid
Asked by
Durga
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mayank
Top achievements
Rank 1
Share this question
or