简体   繁体   中英

telerik radgrid - how do I set the page focus to the insert button after clicking the add new record button to add a record

I have a telerik radgrid that has an allows inserts. After clicking the "Add New Record" button the textboxes appear with a couple of buttons. One for Insert and one to cancel. I would like the page focus to be on the insert button so when the user clicks the enter button, the insert button has the focus.

Does anyone know how to do this?

This isn't tested but I'd assume you'd do it on the ItemCreated event:

Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs)
    If TypeOf e.Item Is GridCommandItem Then

        Dim myButton As LinkButton = TryCast(e.Item.FindControl("myButtonID"), LinkButton)
        myButton.Focus()
    End If
End Sub

Conceptually, it should be possible.

The Add New Record button causes a postback, from my recollection. In that postback, hook into the RadGrid's corresponding event and inject javascript to focus the button.

If you define the edit form through a template, you may also be able to get away with it by using the DefaultButton property on a panel that wraps the editor controls.

I do also agree with Claudio, that Telerik support is great. You may want to start with them as they'll likely give you a complete code sample accomplishing your task.

I found the answer and it is almost like what Markive has, here is the c# version, I am using a ImageButton instead of a LinkButton:

        protected void gvApplications_ItemDataBound(object sender, GridItemEventArgs e)
    {
        //when a user clicks the "Add New" button, 
        //this code puts focus on the Insert button so when the enter key is clicked, the action occurs
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
        {
            GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
            ImageButton btnInsert = (ImageButton)insertItem.FindControl("PerformInsertButton");
            btnInsert.Focus();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM