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

[Solved] Cannot hide a control in GridTemplateColumn

2 Answers 228 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rms
Top achievements
Rank 1
rms asked on 04 Feb 2013, 08:13 PM
Hi,

I have an issue hiding one of the controls in my grid. This is the GridTemplateColumn


<Telerik:GridTemplateColumn UniqueName="Results" DataField="Results" HeaderText="Results" AllowFiltering="false" >  

                     <ItemTemplate>     
                            
                      <asp:LinkButton ID="Upload" runat="server" CommandName= "Edit"
                     Text="Upload" EnableViewState="true">                     
                     </asp:LinkButton>
                  
                     <asp:LinkButton ID="Download" runat="server" CommandName= "Download"  CommandArgument='<%# Eval("Results")%>' Text="Download" EnableViewState="true">                     
                     </asp:LinkButton>
                   
                     </ItemTemplate>

                   <EditItemTemplate>                                          
                                                       
                      <telerik:RadUpload ID="ResultsUpload" runat="server" ControlObjectsVisibility="None" InputSize="55" /> 
                     <asp:LinkButton ID="UploadResults" runat="server" CommandName= "Update"  Text="Upload" EnableViewState="true" />
                   
                   </EditItemTemplate>       
                                  
                     </Telerik:GridTemplateColumn>

I am trying to hide the Download control depending on certain condition. Here's my vb.net code

 Protected Sub Radgrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound

        If TypeOf e.Item Is GridDataItem Then

            Dim eItem As GridDataItem = TryCast(e.Item, GridDataItem)
            Dim filename As String

            For Each item As GridDataItem In RadGrid1.MasterTableView.Items

                Dim Download As LinkButton = TryCast(eItem.FindControl("Download"), LinkButton)
                filename = Download.CommandArgument
                If (Download.CommandArgument = "Not Available" Or Download.CommandArgument = Nothing) Then
                    Download.Visible = False
                Else
                    Download.Visible = True
                End If

            Next
        End If
    End Sub
My problem is I am able to hide all the download linkbuttons except the first row. first row will always shows download button even if the condition is not met.




Any one has any idea about this issue please let me know. Thanks




2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 05 Feb 2013, 03:57 AM
Hi,

Try removing the foreach loop from your code snippet. Please check the following code snippet.

VB:
Protected Sub Radgrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim eItem As GridDataItem = TryCast(e.Item, GridDataItem)
        Dim filename As String = Nothing
        Dim Download As LinkButton = TryCast(eItem.FindControl("Download"), LinkButton)
        filename = Download.CommandArgument
        If (Download.CommandArgument = "Not Available" Or Download.CommandArgument Is Nothing) Then
            Download.Visible = False
        Else
            Download.Visible = True
        End If
    End If
End Sub

Thanks,
Shinu.
0
rms
Top achievements
Rank 1
answered on 05 Feb 2013, 03:43 PM
Thanks for the quick reply Shinu. That did the trick. I got it now.. ItemDatabound is called for every row and there was no need for the loop again.
Tags
Grid
Asked by
rms
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
rms
Top achievements
Rank 1
Share this question
or