I need to show year instade of date string in a HyperLinkField in asp.net WebForms
<asp:HyperLinkField HeaderText="Economic year" DataTextField="Date" SortExpression="Date"DataNavigateUrlFields="Id" DataNavigateUrlFormatString="P_ProfitLossADD.aspx?Id={0}"></asp:HyperLinkField>
but HyperLinkField does not take DataFormatString="{0:d} as property of the control .
答案 0 :(得分:1)
<asp:HyperLinkField HeaderText="Economic year" DataTextField="Date" DataTextFormatString="{0:YYYY}" SortExpression="Date"DataNavigateUrlFields="Id" DataNavigateUrlFormatString="P_ProfitLossADD.aspx?Id={0}"></asp:HyperLinkField>
答案 1 :(得分:0)
Got it you can just use
<asp:TemplateField HeaderText="Economic year">
<ItemTemplate>
<asp:HyperLink ID="Id" runat="server" NavigateUrl='<%# Eval("Id", "P_ProfitLossADD.aspx?id={0}") %>'
Text='<%# Eval("Date","{0:yyyy}") %>'></asp:HyperLink>
</ItemTemplate>
<ItemStyle HorizontalAlign="Right" Wrap="False" />
</asp:TemplateField>