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

Edit mode after insert

2 Answers 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Khanh
Top achievements
Rank 1
Khanh asked on 21 Apr 2010, 08:40 PM
After a successful insert I would like the new record to go into edit/update mode.  The reason is the update template contains a section that exist only if there is a parent record.  So after inserting the parent record exist now I can allow inserting of child records.

Thanks,
Khanh

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Apr 2010, 09:05 AM
Hello Khanh,

You can refer the CodeLibrary Select Last Inserted Row to select the last inserted row. Apply the same logic, but instead of selecting the row set the row in edit mode.

Regards,
Shinu.

0
Khanh
Top achievements
Rank 1
answered on 22 Apr 2010, 04:30 PM
Thanks, Shinu,

That linked really set me on the right track.  Here is my entire grid_prerender code.  Hope this helps others.  This is has two parts.  The first is the parent which after inserting a new record will automatically expand to the details.  When a new details is inserted, it will keep the parent expanded while switching to edit mode.

Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender 
        ' Do nothing if RadGrid is in insert mode or no new item is inserted recently. 
        If RadGrid1.MasterTableView.IsItemInserted OrElse _RequestID <= 0 And _AnnualRequestID <= 0 Then 
            Return 
        End If 
        Dim _ARID As Integer = 0 
        If _AnnualRequestID > 0 Then 
            For Each items As GridDataItem In RadGrid1.Items 
                If items.OwnerTableView.Name = "parentgrid" Then 
                    If _AnnualRequestID.Equals(Convert.ToInt32(items("AnnualRequestID").Text)) Then 
                        items.Expanded = True 
                        ' flag exit 
                        Exit For 
                    End If 
                End If 
            Next 
            Exit Sub 
        End If 
        If _RequestID > 0 Then 
            For Each items As GridDataItem In RadGrid1.Items 
                If items.OwnerTableView.Name = "parentgrid" Then 
                    If _ARID > 0 Then 
                        If _ARID.Equals(Convert.ToInt32(items("AnnualRequestID").Text)) Then 
                            items.Expanded = True 
                            ' flag exit 
                            Exit For 
                        End If 
                    End If 
                End If 
                If items.OwnerTableView.Name = "Prioritization" Then 
                    If _RequestID.Equals(Convert.ToInt32(items("PrioritizationID").Text)) Then 
                        ' Select the last inserted row 
                        _ARID = Convert.ToInt32(items.GetDataKeyValue("AnnualRequestID")) 
                        items.Selected = True 
                        items.Edit = True 
                        ' flag exit 
                        Exit For 
                    End If 
                End If 
            Next 
            RadGrid1.Rebind() 
            Exit Sub 
        End If 
    End Sub 

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