Search code examples
asp.netvb.netvisual-studiodatagridinfragistics

Targeting imagebutton inside template data field in web data grid


I have an ImageButton (ImageButton1) inside a web data grid. I am trying to write an if statement that if the date is less than a certain date then the image button won't be visible. I cannot figure out how to target the ImageButton though. This is the code I have:

 <ig:TemplateDataField Key="Export" CssClass="MinWidth45 Nowrap">
  <Header Text="Map Link"></Header>
  <ItemTemplate>
    <asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="Block(true);" OnClick="ImageButton1_Click" CssClass="Stopper" ImageUrl="~/images/ExcelExport.bmp" Height="25px" Width="24px" ToolTip="Export to Excel" EnableViewState="false"/>
  </ItemTemplate>
 </ig:TemplateDataField>

back-end code(Targeting it by typing it's ID(ImageButton1) doesn't work):

 If e.Row.Items.FindItemByKey("Dates").Value < Date.Today Then

    ImageButton1.visible = False

 End If

Solution

  • If e.Row.Items.FindItemByKey("Dates").Value < Date.Today Then
    
       e.Row.Items(13).FindControl("ImageButton1").Visible = False
    
    End If
    

    "(13)" being the index of the column in my data table