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

make Image dissapear if nothing for linkbutton

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 29 Mar 2012, 08:39 PM
So I have a print image as part of my radgrid.  What I want to do is hide the image button of there is nothing existing for the linkbutton becuase I hide duplicates of the link button.  So where the linkbutton is not there I want to also hide the printer image.

<telerik:RadGrid ID="myRadGridFin" runat="server" Width="100%" BorderWidth="1px" CellPadding="6" GridLines="None" BorderColor="#404040" Skin="Web20">
                                   <MasterTableView AutoGenerateColumns="false" DataKeyNames="intRecId" Name="MasterGrid" BorderColor="#404040" Font-Size="9" Font-Names="Veranda,arial,sans-serif"
                                       HeaderStyle-HorizontalAlign="Center" GridLines="Both" BorderWidth="1px"><AlternatingItemStyle BackColor="#B0C4DE"  HorizontalAlign="Center" /><ItemStyle HorizontalAlign="Center" />
                                       <HeaderStyle ForeColor="White" Font-Bold="true" BorderColor="#404040" BorderWidth="1px" />
                                           <Columns>
                                               <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ConfirmText="Are you sure you want to delete item from turn-in" />
                                               <telerik:GridTemplateColumn>
                                                   <ItemTemplate>
                                                       <asp:Image ID="imgPrint" runat="server" ImageUrl="~/Images/Printer.png" style="cursor:pointer" />
                                                   </ItemTemplate>
                                               </telerik:GridTemplateColumn>
                                               <telerik:GridTemplateColumn HeaderText="DDN">
                                                   <ItemTemplate>
                                                       <asp:LinkButton ID="lnkAdd" runat="server" Text='<%# bind("strDDN") %>' ToolTip="Click to Add Equipment to Doc Number" CommandName="Add" CommandArgument='<%#Bind ("strDDN") %>'></asp:LinkButton>
                                                   </ItemTemplate>
                                               </telerik:GridTemplateColumn>
                                               <telerik:GridTemplateColumn HeaderText="CATEGORY">
                                                   <ItemTemplate>
                                                       <asp:Label ID="lblCategory" runat="server" Text='<%# Bind("strCategory") %>'></asp:Label>
                                                       <asp:Label ID="lblCatId" runat="server" Text='<%#bind ("intCategoryId") %>' Visible="false"></asp:Label>
                                                   </ItemTemplate>
                                               </telerik:GridTemplateColumn>
                                               <telerik:GridBoundColumn DataField="strSN" HeaderText="SN" />
                                               <telerik:GridBoundColumn DataField="Equip" HeaderText="EQUIPMENT" />
                                               <telerik:GridBoundColumn DataField="Location" HeaderText="LOCATION" />
                                           </Columns>
                                   </MasterTableView>
                               </telerik:RadGrid>



Protected Sub myRadGridFin_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles myRadGridFin.ItemDataBound
       If (TypeOf e.Item Is GridDataItem) Then
           Dim img As Image = e.Item.FindControl("imgPrint")
           Dim lnk As LinkButton = e.Item.FindControl("lnkAdd")
           If lnk.Text = " " Then
               img.Enabled = False
               img.Visible = False
           End If
       End If
   End Sub


I also tried using it as an e.item.cell(?).text but this did not work either becuase it sees it as a linkbutton column I believe.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 30 Mar 2012, 05:32 AM
Hi Kevin,

Try removing the space in between the double quotes. Here is the code snippet that worked for me.

VB:
Protected Sub myRadGridFin_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim img As Image = DirectCast(item.FindControl("imgPrint"), Image)
        Dim lnk As LinkButton = DirectCast(item.FindControl("lnkAdd"), LinkButton)
        If lnk.Text = "" Then
            img.Enabled = False
            img.Visible = False
        End If
    End If
End Sub

Regards,
-Shinu.
0
Kevin
Top achievements
Rank 1
answered on 30 Mar 2012, 03:25 PM
Hi,
thanks, I see what the difference is, i guess i need to stop being lazy and call everything out as a griddataitem, but I thought the top statement was doing this for me.  thanks for your help, awesome.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Share this question
or