0

I want to pass the variable Date to my function HasBtnRights(). Any suggestions on how to do that?

<asp:TemplateField HeaderText="More info" Visible='<%#HasBtnRights(Eval("Date")) %>'>
    <ItemTemplate>
        <asp:Button runat="server" OnClientClick='openModalPopup(<%# Eval("Agreement")%>);' Text="Open"/>
    </ItemTemplate>
</asp:TemplateField>
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Jedi Schmedi
  • 746
  • 10
  • 36
  • Is `HasBtnRights` a JavaScript function, or a method in your code behind? Does your current code give you an error? – mason Sep 17 '15 at 13:16
  • check this out... http://stackoverflow.com/questions/4954871/how-to-hide-a-templatefield-column-in-a-gridview – g2000 Sep 17 '15 at 13:58

1 Answers1

0

If you want to hide / show the button based on certain criteria, you can set the Visible property of the Button itself.

<asp:TemplateField HeaderText="More info" >
    <ItemTemplate>
        <asp:Button runat="server" Visible='<%#HasBtnRights(Eval("Date")) %>'  OnClientClick='openModalPopup(<%# Eval("Agreement")%>);' Text="Open" />
    </ItemTemplate>
</asp:TemplateField>

An then, in your code behind:

public bool HasBtnRights(DateTime myDate) {
    // your date logic here
    return true; // or return false;
}
Olivier De Meulder
  • 2,493
  • 3
  • 25
  • 30