Set Date Visible condition in LinkButton

2020-04-30 18:24发布

问题:

Set Date Visible condition in LinkButton Using ASP.NET C# Web Forms. I have a GridView. In GridView Template field using LinkButton. I want to match the condition batchdate less than and equal to then only LinkButton should visible true.

Below is my LinkButton's code. I know wrote wrong visibility condition.

<asp:LinkButton ID="lnkbtn_ViewCan" runat="server"
Text="View Candidates" OnClick="lnkbtn_ViewCan_Click" Visible='<%# Eval("BatchDate").ToString() <= DateTime.Now %>'  ></asp:LinkButton>

In database table BatchDate values is storing like below

2016-10-26 00:00:00.000

回答1:

Use this:

In ASPX:

Visible='<%#GetVisible(Eval("BatchDate").ToString())%>'

And in the code behind:

public bool GetVisible(object value)
{
    if (Convert.ToDateTime(value) <= DateTime.Now)
    {
        return true;
    }
    return false;
}


标签: c# asp.net