views:

26

answers:

1

Hi, I have an LinkButton column in my GridView:

<Columns>
     <asp:TemplateField>
         <ItemTemplate>
              <asp:LinkButton runat="server"/>
         </ItemTemplate>
     </asp:TemplateField>
</Columns>

let's assume that I need to bound to that GridView a list of some items, where some of them shoud have visible that LinkButton, some not. So that is the question: how - while bounding/after bound - can I realize that scenario, I mean show LinkButtons (with different CommandArgument) where there are needed ?

+2  A: 

You have 3 options:

  1. Handle the RowDataBound event: find the button in the row and set the visible property
  2. Bind a property/column in the datasource: <asp:LinkButton Visible='<%# Bind("Editable") %>'
  3. create a method returning a boolean in the page and use it: <asp:LinkButton Visible='<%# IsButtonVisible(DataBinder.Eval(Container.DataItem, "ID")) %>'
onof