C# ASP.NET在ASP:GridView中使用代理值
我有一个asp:GridView,在其中一列中C# ASP.NET在ASP:GridView中使用代理值,c#,html,asp.net,C#,Html,Asp.net,我有一个asp:GridView,在其中一列中 <asp:TemplateField AccessibleHeaderText="Created" ItemStyle-Wrap="false"> <ItemTemplate> <asp:LinkButton ID="lnkTimeline" runat="server" CausesValidation="False" CommandName="Continue" CommandArgumen
<asp:TemplateField AccessibleHeaderText="Created" ItemStyle-Wrap="false">
<ItemTemplate>
<asp:LinkButton ID="lnkTimeline" runat="server" CausesValidation="False" CommandName="Continue" CommandArgument='<%# Container.DataItemIndex %>' Text='<%# CreatedAt_Proxy %>'></asp:LinkButton>
</ItemTemplate>
代理人:
public string CreatedAt_Proxy
{
get
{
string rv = "";
int secondsPast = (int)DateTime.UtcNow.Subtract(CreatedAt).TotalSeconds;
int threshold = 5 * 24 * 60 * 60;
if (secondsPast >= threshold) rv = "<span style='color: red'>";
rv += E.HourFormat(secondsPast, false) + " ago";
rv += "<br />" + CreatedAt.ToString("dd.MM.yyyy HH:mm");
if (secondsPast >= threshold) rv += "</span>";
return rv;
}
}
公共字符串CreatedAt\u代理
{
得到
{
字符串rv=“”;
int secondsPast=(int)DateTime.UtcNow.Subtract(CreatedAt.TotalSeconds;
整数阈值=5*24*60*60;
如果(secondsPast>=阈值)rv=“”;
rv+=E.HourFormat(secondsPast,false)+“ago”;
rv+=“
”+CreatedAt.ToString(“dd.MM.yyyy HH:MM”);
如果(secondsPast>=阈值)rv+=“”;
返回rv;
}
}
我想在may gridview(
Text='
)中使用该代理,以便生成包含不同时间的文本链接 您可以钩住RowDataBound事件来呈现所需的数据
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkTimelineButton = e.Row.FindControl("lnkTimeline") as LinkButton ;
lnkTimelineButton.Text= GetProxyTime();
}
//创建以下函数并获取proxytime的值
private string GetProxyTime()
{
string rv = "";
int secondsPast = (int)DateTime.UtcNow.Subtract(CreatedAt).TotalSeconds;
int threshold = 5 * 24 * 60 * 60;
if (secondsPast >= threshold) rv = "<span style='color: red'>";
rv += E.HourFormat(secondsPast, false) + " ago";
rv += "<br />" + CreatedAt.ToString("dd.MM.yyyy HH:mm");
if (secondsPast >= threshold) rv += "</span>";
return rv;
}
私有字符串GetProxyTime()
{
字符串rv=“”;
int secondsPast=(int)DateTime.UtcNow.Subtract(CreatedAt.TotalSeconds;
整数阈值=5*24*60*60;
如果(secondsPast>=阈值)rv=“”;
rv+=E.HourFormat(secondsPast,false)+“ago”;
rv+=“
”+CreatedAt.ToString(“dd.MM.yyyy HH:MM”);
如果(secondsPast>=阈值)rv+=“”;
返回rv;
}