我正在尝试将 GA 跟踪代码添加到 Datalist 控件内部的超链接中,使用以下代码我可以添加,但是所有 GA 跟踪事件将显示所有 pdf 文件将具有相同的名称。下面是代码
<asp:DataList ID="dlTournamentMenu" runat="server" RepeatColumns="4"
CellSpacing="5" RepeatLayout="Table" SeparatorStyle-Width="10" CellPadding="4"
BorderWidth="0" >
<ItemTemplate>
<div class="uc4TournamentLinks" >
<asp:HyperLink ID="hylMenuItem" runat="server" NavigateUrl='<%# Eval("PageInternalLinkURL") %>' ToolTip='<%# Eval("PageName") %>' onclick="_gaq.push(['_trackEvent', 'Downloads', 'PDF', 'PDF File Downloaded']);" Target='<%# Eval("PageWindow") %>' BorderWidth="0px" Font-Underline="False" >
<asp:Label ID="lblTourTitle" CssClass="uc4TournamentLinksColor" runat="server" Text='<%# Eval("PageName") %>'></asp:Label>
</asp:HyperLink>
</div>
</ItemTemplate>
</asp:DataList>
当我尝试添加如下代码时
onclick="_gaq.push(['_trackEvent', 'Downloads', 'PDF', '<%# Eval("PageWindow") %>']);"
它会产生错误,因为我无法将 Eval 绑定到此属性。
我怎样才能像我们为Repeater控件做的那样在语法上绑定它,如下例所示
protected void gvUsers_RowDataBound(object sender, GridViewRowEventArgs e)
{
//LOCK USER
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lbLockUser = e.Row.FindControl("lnkBtnLockUser") as LinkButton;
if (lbLockUser != null)
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lbLockUser);
lbLockUser.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to lock this User ')");
}
}