forum

Home / DeveloperSection / Forums / How to hide ImageButton based on Row Cell value?

How to hide ImageButton based on Row Cell value?

Samuel Fernandes 1856 12-Apr-2015

I am trying to hide my imagebutton based on the cell value of another column.

So if my cell value.Text = "OPEN" then I want that specific imagebutton for that row to be invisible.

However my code 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


Updated on 13-Apr-2015

Can you answer this question?


Answer

1 Answers

Liked By