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

Need alternative for GetInsertItem method for editmode

2 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
nfigueroa
Top achievements
Rank 1
nfigueroa asked on 15 Jul 2014, 05:55 PM
I have a grid which uses the pop-up inline insert and edit form.  In it a have a dropdown list that updates a text box in the form after a selection from it.  The problem I have is that I have no alternative to the GetInsertItem method on the grid object.  I have researched for alternatives but so far all examples leads to either the UpdatedCommand or ItemCreated or ItemCommand events, which don't apply to my case.  Here's my code.

Private Sub RGExpenses_ItemCreated(sender As Object, e As GridItemEventArgs) Handles RGExpenses.ItemCreated
    If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
        Dim list As DropDownList = CType(CType(e.Item, GridEditableItem
​Description").Controls(0), DropDownList)
        list.AutoPostBack = True
        AddHandler list.SelectedIndexChanged, AddressOf list_SelectedIndexChanged
        SetAmount(list)
    End If
End Sub
 
Private Sub list_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    'sets Item amount when change selected value
    SetAmount(CType(sender, DropDownList))
End Sub
 
Private Sub SetAmount(ByVal ddl As DropDownList)
    If Not IsNothing(ddl.SelectedItem) Then
        Dim decPAmount As Decimal = cDB.dbConsult(Application("db"), "SELECT TOP 1 Amount FROM Table1)
        If RGExpenses.MasterTableView.IsItemInserted Then
            CType(RGExpenses.MasterTableView.GetInsertItem.FindControl("TB_Amount"), TextBox).Text = decPAmount
        Else
            'here is where I need to find the control, but no method to do so
            CType(RGExpenses.MasterTableView.FindControl("TB_Amount"), TextBox).Text = decPAmount
        End If
    End If
End Sub

So as you can see, there is no problem on insert mode.  Incredibly, the problem is that I have no method for Edit mode to replicate what I'm doing on insert mode.  How can I reference the text box control within the edit form when in edit mode.

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Jul 2014, 06:05 AM
Hi,

I guess you want to display different values on Insert and EditMode, you can try the following code snippet:

VB:
Private Sub list_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim ddlDescription As DropDownList = DirectCast(sender, DropDownList)
    Dim editItem As GridEditableItem = DirectCast(ddlDescription.NamingContainer, GridEditableItem)
    Dim txtAmount As TextBox = DirectCast(editItem.FindControl("TB_Amount"), TextBox)
    If RadGrid1.MasterTableView.IsItemInserted Then
        txtAmount.Text = "Your Insert Value"
    Else
        txtAmount.Text = "Your Edit Value"
    End If
End Sub

Thanks,
Princy
0
nfigueroa
Top achievements
Rank 1
answered on 16 Jul 2014, 02:05 PM
Thanks Princy

Did not occurred to me to access the objects through their NamingContainer method.  Sometimes the answer is so simple.
Tags
Grid
Asked by
nfigueroa
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
nfigueroa
Top achievements
Rank 1
Share this question
or