【问题标题】:Find Unique Identifier From Selected Item In ASP ListView从 ASP ListView 中的选定项目中查找唯一标识符
【发布时间】:2010-09-01 22:35:28
【问题描述】:

我正在使用 ListView 并有两个按钮,允许用户从列表中删除或编辑项目。下面是按钮的代码:

<td>
   <asp:ImageButton ID="ButtonEdit" runat="server" ImageUrl="~/Styles/Images/Edit.png" ToolTip="Edit" OnClick="ButtonEdit_Click" />
   <asp:ImageButton ID="ButtonDelete" runat="server" ImageUrl="~/Styles/Images/Delete-Red-Cross.png" ToolTip="Delete" CommandName="Delete" />
 </td>

当用户单击编辑按钮时,我想将列表中项目的唯一标识符传递给参数字符串,以便我可以在编辑页面中检索它。有人对如何从所选项目中检索 ID 有任何想法吗?

【问题讨论】:

  • 你可以为你的列表视图发布完整的 html 吗?

标签: asp.net listview listviewitem


【解决方案1】:

你可以使用ImageButton.CommandArgument property:

<td> 
   <asp:ImageButton ID="ButtonEdit" runat="server" ImageUrl="~/Styles/Images/Edit.png" ToolTip="Edit" OnClick="ButtonEdit_Click" CommandArgument='<%= ItemBeingOutput.ID %>'/> 
   <asp:ImageButton ID="ButtonDelete" runat="server" ImageUrl="~/Styles/Images/Delete-Red-Cross.png" ToolTip="Delete" CommandName="Delete" CommandArgument='<%= ItemBeingOutput.ID %>'/> 
 </td> 

【讨论】:

    【解决方案2】:

    我想出了如何在没有 PostBackUrl 属性的情况下传递 Eval:

    <asp:ImageButton ID="ButtonEdit" runat="server" ImageUrl="~/Styles/Images/Edit.png"
                            ToolTip="Edit" PostBackUrl='<%# string.Format("system/editsystem.aspx?SystemID={0}", Eval("SystemID")) %>' />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 2019-10-26
      • 1970-01-01
      • 2015-02-26
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多