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

Accessing controls in EditForm Template New Record

1 Answer 6 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Ric asked on 18 Dec 2015, 03:02 PM

Hello All,

Hopefully this has an easy solution. I'm using a RadGrid with an EditForm (EditFormType="Template"). In that form I have a dropdownlist and several other fields. Depending on the value selected in the ddl, I need to enable or disable certain validators. the following code for SelectedIndexChanged works when in edit mode, but does not when in insert mode. How do I get it to fire for Insert as well as Edit?


    Protected Sub lstContactType_SelectedIndexChanged(sender As Object, e As EventArgs)

        For Each item As GridDataItem In gridEmpContacts.EditItems
            ' Access your textbox here
            Dim rfv1 As RequiredFieldValidator = TryCast(item.EditFormItem.FindControl("rfvSSN"), RequiredFieldValidator)
            Dim rfv2 As RequiredFieldValidator = TryCast(item.EditFormItem.FindControl("rfvPctBene"), RequiredFieldValidator)
            Dim rfv3 As RequiredFieldValidator = TryCast(item.EditFormItem.FindControl("rfvContactDoB"), RequiredFieldValidator)
            Dim listbox As DropDownList = DirectCast(sender, DropDownList)

            Select Case listbox.SelectedValue
                Case "401K/Profitsharing - Primary", "401K/Profitsharing - Secondary", "Life - Primary", "Life - Secondary", "AD&D - Primary", "AD&D - Secondary"
                    rfv1.Enabled = True
                    rfv2.Enabled = True
                    rfv3.Enabled = True
                Case Else
                    rfv1.Enabled = False
                    rfv2.Enabled = False
                    rfv3.Enabled = False
            End Select

    End Sub

1 Answer, 1 is accepted

Sort by
Viktor Tachev
Telerik team
answered on 21 Dec 2015, 01:15 PM
Hi Ric,

Note that the EditItems collection includes only the items that are in edit mode. The insert item is not included in it. If you would like to get the insert item you would need to use the GetInsertItem() method of the GridTableView.

If RadGrid1.MasterTableView.IsItemInserted Then
    Dim insertItem = RadGrid1.MasterTableView.GetInsertItem()
    ' add custom logic here
End If

Viktor Tachev
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question