【发布时间】:2019-01-02 12:39:04
【问题描述】:
我需要为面板列表中的每个项目添加一个“下载”按钮。每个下载按钮都应将唯一的 ID 传递给事件处理程序。
新按钮的问题:ID=DownloadPopup_btn_1 是它没有将请求发送到带有我想要的参数的事件处理程序。
我尝试使用 方法,但它以空字符串或纯文本“item.PromotionId”的形式发送参数(取决于我是否使用了“”)。
我不能使用 因为“item”没有定义。
<ul id="draggablePanelList" class="list-group">
<% var popupIndex = 0;
foreach (var item in OldGameSettings.PromotionalDataList)
{
popupIndex++;
%>
<li class="list-group-item sortable-item first">
<asp:LinkButton ID="DownloadPopup_btn_1"
runat="server"
CssClass="btn btn-default pull-right btn-xs"
OnCommand="DownloadPopup_Click"
CommandArgument='<%#Eval(item.PromotionId)%>'>
<span aria-hidden="true" class="glyphicon glyphicon-download-alt"></span>
</asp:LinkButton>
<span style="margin-right: 15px;" class="pull-right">
<i class="glyphicon glyphicon-chevron-up" style="cursor: pointer; cursor: hand;" onclick="sendToTopPriority(this)" id="<%=item.PromotionId %>"></i>
<i class="glyphicon glyphicon-chevron-down" style="cursor: pointer; cursor: hand;" onclick="sendToBottomPriority(this)" id="<%=item.PromotionId %>"></i>
<i class="glyphicon glyphicon-chevron-right" style="cursor: pointer; cursor: hand;" onclick="sendToPriority(this)" id="<%=item.PromotionId %>"></i>
</span>
</li>
<% } %>
</ul>
预期:点击面板列表中的 N'ish 下载按钮,该按钮将触发带有 CommandArgument == Button[N].CommandArgument 的事件处理程序
实际:点击面板列表中的N'ish下载按钮,该按钮触发事件处理程序CommandArgument ==不是我想要的...
附:我在代码中添加了最后一部分以证明 item.PromotionId 在不同的元素中有效。
【问题讨论】:
-
CommandArgument == not what I want...CommandArgument到底得到了什么? -
你可以试试
<%=item.PromotionId %>而不是'<%#Eval(item.PromotionId)%> -
@ChetanRanpariya 我得到一个空字符串或 的纯文本。我尝试了您的建议,但在这种情况下项目未知。
-
@EtianChamay,您是否在代码或其 100% 内联 C# 代码中使用 Page_Load 等服务器端事件?