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

[Solved] Default to Edit Mode and set focus

4 Answers 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 28 Sep 2009, 05:02 PM
I've setup a radgrid to open in edit mode but also want the focus to be on a specific text box "Allowed" on the first row of the radgrid.The following code sets the radgrid to edit, but i have been unsuccessful in getting any of the focus routines to work correctly.

 

Private Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender

 

 

    If Not IsPostBack Then

 

 

        For Each item As GridItem In RadGrid1.MasterTableView.Items

 

 

            If TypeOf item Is GridEditableItem Then

 

 

                Dim editableItem As GridEditableItem = CType(item, GridDataItem)

 

                editableItem.Edit =

True

 

 

            End If

 

 

        Next

 

        RadGrid1.Rebind()

 

    End If

 

 

End Sub

Any suggestions would be appreciated.

 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Sep 2009, 05:07 AM
Hi Paul,

Try the following code snippet in order to focus the textbox in the fist row which is in editmode.

CS:
 
Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) 
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.ItemIndex = 0 AndAlso e.Item.IsInEditMode Then 
        Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) 
        Dim text As TextBox = DirectCast(item("CustomerID1").Controls(0), TextBox) 
        text.Focus() 
    End If 
End Sub 
 

-Shinu.
0
Paul
Top achievements
Rank 1
answered on 29 Sep 2009, 07:28 PM

Shinu -

 

Thanks for the reply. It seems that I never get to the ItemDataBound sub. When I walk through the code, the PreRender runs through and the page is displayed.

Am I missing something here?

Thanks

Paul

0
Shinu
Top achievements
Rank 2
answered on 26 Oct 2009, 12:18 PM
Hello Paul,

Make sure that you have added the onItemDataBound event in the aspx as shown below:
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1"  
AutoGenerateColumns="false" runat="server" OnItemDataBound="RadGrid1_ItemDataBound"

Thanks
Shinu.
0
Paul
Top achievements
Rank 1
answered on 26 Oct 2009, 03:51 PM
Shinu,

Thanks for the reply. That is exactly what was missing.

Paul
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Paul
Top achievements
Rank 1
Share this question
or