Need alternative for GetInsertItem method for editmode

3 posts, 1 answers
  1. nfigueroa
    nfigueroa avatar
    21 posts
    Member since:
    Apr 2010

    Posted 15 Jul 2014 Link to this post

    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. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Jul 2014 in reply to nfigueroa Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. nfigueroa
    nfigueroa avatar
    21 posts
    Member since:
    Apr 2010

    Posted 16 Jul 2014 in reply to Princy Link to this post

    Thanks Princy

    Did not occurred to me to access the objects through their NamingContainer method.  Sometimes the answer is so simple.
Back to Top