Hide or show ImageButton in gridview

Posted on 2009-02-12
Last Modified: 2012-05-06
Hi All

I have a gridview with imagebuttons (code attached) what I want to to is show or hide the second button based on a flag in a database.

I know I have to do it in the rowdatabound event and I have the flag to test, but how do I write the show / hide part.

<asp:TemplateField ShowHeader="False">


                        <asp:ImageButton ID="btnViewDemog" runat="server" OnClick="btnViewDemog_Click"  ImageUrl="~/images/CheckDemog.gif" Height="20" Width="20" CausesValidation="false" />


                        <asp:ImageButton ID="btnViewOutcomes" runat="server" OnClick="btnViewOutcomes_Click"  ImageUrl="~/images/ViewOutcomes.gif" Height="20" Width="20" CausesValidation="false"/>




                    <ItemStyle Wrap="False" />



Open in new window

Question by:Andy Green
    LVL 13

    Accepted Solution

    something like this

     if (e.Row.RowType = DataControlRowType.DataRow) Then

    if ( DataBinder.Eval(e.Row.DataItem,  "FieldName").ToString().Equal("SomethingToTest") ) Then
    end if
    End if
    LVL 3

    Author Closing Comment

    by:Andy Green
    Fantastic, thank you.


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now