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

Cannot set control to 'visible=false' in radgrid

4 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard M
Top achievements
Rank 1
Richard M asked on 07 Jun 2010, 08:26 PM
Is there a way to hide a control inside a radgrid in Edit Mode?  I have tried the following code below, but the controls are still showing:

Private Sub RadGrid1_EditCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.EditCommand
      If TypeOf e.Item Is GridDataItem Then

            Dim btn_Row_Options As Button = e.Item.FindControl("btn_Row_Options")
            btn_Row_Options.Visible = False

            Dim btn_Row_Options As Button = DirectCast(e.Item.FindControl("btn_Row_Options"), Button)
            btn_Row_Options.Visible = False

    End If
End Sub

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Jun 2010, 05:25 AM
Hello Richard,

Try the following code snippet in ItemDataBound event to hide the control in edit mode.

VB.Net:
 
 Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) 
    If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then 
        Dim edititem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem) 
        Dim btn As Button = DirectCast(edititem.FindControl("btn_Row_Options"), Button) 
        btn.Visible = False 
    End If 
 End Sub 
 

Regards,
Shinu.


0
Richard M
Top achievements
Rank 1
answered on 08 Jun 2010, 06:16 PM
Shinu,
The code did not break at 'Dim edititem As GridEditFormItem'.

(here's the rows referred to in my RadGrid)

<telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
<ItemTemplate>
<asp:Button  ID="btn_Row_Options" runat="server" Text="Options" />
</ItemTemplate>
</telerik:GridTemplateColumn>

<telerik:GridTemplateColumn UniqueName="TemplateColumn">
<EditItemTemplate>
<asp:Button runat="server" CommandName="Update" Text="Update" />&nbsp;
<asp:Button runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:Button runat="server" CausesValidation="false" CommandName="Edit" Text="Edit" OnClientClick="hide_Options()" />
</ItemTemplate>
</telerik:GridTemplateColumn>


0
Shinu
Top achievements
Rank 2
answered on 09 Jun 2010, 08:10 AM
Hello Richard,

I hope the following code will help you.

VB.Net:
 
 Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) 
    If RadGrid1.EditIndexes.Count > 0 AndAlso TypeOf e.Item Is GridDataItem Then 
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
        Dim btn As Button = DirectCast(item.FindControl("btn_Row_Options"), Button) 
        btn.Visible = False 
    End If 
 End Sub 
 

Regards,
Shinu.



0
Richard M
Top achievements
Rank 1
answered on 09 Jun 2010, 07:39 PM
That works!  Thank you.
Tags
Grid
Asked by
Richard M
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Richard M
Top achievements
Rank 1
Share this question
or