views:

12

answers:

2

I'm using a ListView and have two buttons that allows users to delete or edit a item from the list. Below is the code for the buttons:

<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>

When the user clicks the edit button I want to pass the unique identifier from the item in the list to the parameter string so I can retrieve it in the edit page. Does anyone have any ideas on how to retrieve the ID from the selected item?

A: 

I figured out how to pass the Eval without the PostBackUrl property:

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

You could use the 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> 
Joel Etherton