Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 646
  • Last Modified:

Hide or show ImageButton in gridview

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.

Andy
<asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <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"/>
                    
                    </ItemTemplate>
                    
                    <ItemStyle Wrap="False" />
                    
                </asp:TemplateField>

Open in new window

0
Andy Green
Asked:
Andy Green
1 Solution
 
sm394Commented:
something like this

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

if ( DataBinder.Eval(e.Row.DataItem,  "FieldName").ToString().Equal("SomethingToTest") ) Then
e.Row.FindControl("YourButton1").visible=true;
e.Row.FindControl("YourButton2").visible=false;
end if
End if
0
 
Andy GreenAuthor Commented:
Fantastic, thank you.

Andy
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now