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

[Solved] Hide or Show controls in editmode

1 Answer 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 03 Mar 2010, 07:05 PM
I am trying to hide or display different controls in edit mode depending on the value of another item
Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated  
        If e.Item.IsInEditMode AndAlso Not (TypeOf e.Item Is IGridInsertItem) Then 
            Dim formItem As GridEditFormItem = CType(e.Item, GridEditFormItem)  
            Dim mydd As DropDownList = TryCast(e.Item.FindControl("DropDownList1"), DropDownList)  
            Dim mytb As TextBox = TryCast(e.Item.FindControl("TextBox1"), TextBox)  
            If formItem("DataType").Text = "List-Text" Then 
                mydd.Visible = True 
                mytb.Visible = False 
            End If 
        End If 
    End Sub 
This code is not working the textbox is visible no matter what value is in DataType

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Mar 2010, 05:21 AM
Hello Rick,

Try accessing the GridDataItem using formItem.ParentItem property and check for the condition as shown below.

C#:
 
Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs) 
    If e.Item.IsInEditMode AndAlso Not (TypeOf e.Item Is IGridInsertItem) Then 
        Dim formItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem) 
        Dim mydd As DropDownList = TryCast(e.Item.FindControl("DropDownList1"), DropDownList) 
        Dim mytb As TextBox = TryCast(e.Item.FindControl("TextBox1"), TextBox) 
        If formItem.ParentItem("DataType").Text = "List-Text" Then 
            mydd.Visible = True 
            mytb.Visible = False 
        End If 
    End If 
End Sub 

Best regards,
Shinu.
Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or