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

Accessing Edit Form controls

3 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adonis
Top achievements
Rank 1
Adonis asked on 06 Oct 2010, 07:07 AM
Hello ,

  I am trying to access controls in an edit form to render the visibility of certain controls I tried the following but cannot find the controls ,

Public Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemEvent
        If TypeOf (e.Item) Is GridEditFormInsertItem Then
            Dim item As GridEditFormInsertItem = CType(e.Item, GridEditFormInsertItem)
            Dim panel As Panel = DirectCast(item.FindControl("Panel1"), Panel)
            Dim cmbDataType As RadComboBox = DirectCast(item.FindControl("DataTypeDropDown"), RadComboBox)
            If cmbDataType.SelectedValue = "Choice" Then
                panel.Visible = True
            Else
                panel.Visible = False
            End If
        End If



what would be the proper method to access the controls?

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Oct 2010, 07:40 AM
Hello Adonis,

Access the control in ItemDataBound event and set its visibility accordingly.

VB.Net:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
        'access edit form
        Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
        Dim panel As Panel = DirectCast(item.FindControl("Panel1"), Panel)
        Dim cmbDataType As RadComboBox = DirectCast(item.FindControl("DataTypeDropDown"), RadComboBox)
        If cmbDataType.SelectedValue = "Choice" Then
            panel.Visible = True
        Else
            panel.Visible = False
        End If
    End If
 
    If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.OwnerTableView.IsItemInserted Then
        ' access insert form
        Dim item As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
        Dim panel As Panel = DirectCast(item.FindControl("Panel1"), Panel)
        Dim cmbDataType As RadComboBox = DirectCast(item.FindControl("DataTypeDropDown"), RadComboBox)
        If cmbDataType.SelectedValue = "Choice" Then
            panel.Visible = True
        Else
            panel.Visible = False
        End If
    End If
End Sub

Thanks,
Princy.
0
Adonis
Top achievements
Rank 1
answered on 06 Oct 2010, 02:49 PM
Thanks that worked great, I also wanted to reverse the option of hiding the panel if the selected index changed of the RadComboBox, right now I am doing it rather clumsy by rebinding the grid in the Selected index changed event for the radcombobox,I imagine there is a better way to accomplish that?
0
Princy
Top achievements
Rank 2
answered on 07 Oct 2010, 08:08 AM
Hello Adonis,

In SelectedIndexChanged event of RadComboBox, access RadComboBox first and using NamingContainer property of RadComboBox, get the GridEditFormItem. Then using FindControl method access the panel and set its visibility accordingly.

VB.Net:
Protected Sub RadComboBox1_SelectedIndexChanged(o As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
    Dim combo As RadComboBox = DirectCast(o, RadComboBox)
    Dim editItem As GridEditFormItem = DirectCast(combo.NamingContainer, GridEditFormItem)
    Dim panel As Panel = DirectCast(item.FindControl("Panel1"), Panel)
    If combo.SelectedValue = "Choice" Then
        panel.Visible = True
    Else
        panel.Visible = False
    End If
End Sub

Thanks,
Princy.
Tags
Grid
Asked by
Adonis
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Adonis
Top achievements
Rank 1
Share this question
or