---
title: "How to hide ImageButton based on Row Cell value?"  
description: "How to hide ImageButton based on Row Cell value?"  
author: "Samuel Fernandes"  
published: 2015-04-12  
updated: 2015-04-13  
canonical: https://www.mindstick.com/forum/23092/how-to-hide-imagebutton-based-on-row-cell-value  
category: ".net"  
tags: ["c#", "asp.net"]  
reading_time: 2 minutes  

---

# How to hide ImageButton based on Row Cell value?

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to hide my [imagebutton](https://www.mindstick.com/articles/12753/imagebutton-in-android) based on the [cell value](https://www.mindstick.com/forum/33654/send-table-view-cell-value-on-button-action-in-ios) of another column.

So if my cell value.[Text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) = "OPEN" then I want that specific imagebutton for that [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) to be invisible.

However my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) hides all of the imagebuttons and I just wanna hide the ones that contain the cell text "OPEN"

## Here is the code I have:

```
<asp:GridView ID="gvv" OnRowDataBound="gv1_RowDataBound" onrowcommand="gridupdate_RowCommand"  OnPreRender="GridView1_PreRender" class="table table-striped table-bordered table-hover" runat="server">   <Columns>   <asp:TemplateField HeaderStyle-Width ="115px" HeaderText="Action">    <ItemTemplate><asp:ImageButton ID="ImageButton3" runat="server"  CommandName="Submit" ImageUrl="~/img/Sumbit.png" /><asp:ImageButton ID="ImageButton2" runat="server" CommandName="ASN" ImageUrl="~/img/ASN-send.png" /><asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/img/invoice.png" CommandName="View" />&nbsp;</ItemTemplate><HeaderStyle Width="115px"></HeaderStyle>       </asp:TemplateField>           </Columns>            </asp:GridView>Backend Code:Protected Sub gv1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)        If (e.Row.RowType = DataControlRowType.DataRow) Then            If (e.Row.Cells(2).Text.ToString = "OPEN") Then            Else                Dim imgBtn As ImageButton = CType(e.Row.FindControl("ImageButton3"), ImageButton)                imgBtn.Visible = False            End If        End If    End Sub
```

## Replies

### Reply by Anonymous User

I think your code works correctly but you just need to revise your If statement, it should be:

```
Protected Sub gv1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)        If(e.Row.RowType = DataControlRowType.DataRow) Then            If(e.Row.Cells(2).Text.ToString = "OPEN") Then               'Hide ImageButton3               Dim imgBtn As ImageButton = CType(e.Row.FindControl("ImageButton3"),
ImageButton)              
imgBtn.Visible = False            Else                'Do nothing            End If        End If    End Sub
```

Tried it on my side and it's working, unless you are doing something else in GridView1_PreRender method that maybe affect on this.


---

Original Source: https://www.mindstick.com/forum/23092/how-to-hide-imagebutton-based-on-row-cell-value

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
