2012-06-27 2 views
0

У меня есть список ListView1, и он связан с моей таблицей клиентов в моей базе данных клиента mssql. Теперь я добавил OnItemDeleting= "ArchiveBeforeDelete" в Listview, потому что хочу, чтобы клиент был заархивирован (перемещен в таблицу клиента базы данных моего архивного клиента), прежде чем он будет удален из обычной базы данных. Мне удалось получить выбранный индекс, используя e.ItemIndex, но теперь я не могу понять, как извлечь данные, а точнее только часть CustomerID, используя индекс. Я просмотрел свойства и методы и не могу найти тот, который работает.Извлечение данных из списка

EDIT: Вот код на странице .aspx для ListView

<asp:ListView ID="ListView1" runat="server" DataKeyNames="CustomerId" 
    DataSourceID="SqlDataSource1" OnItemDeleting= "ArchiveBeforeDelete"> 
    <AlternatingItemTemplate> 
     <tr style="background-color: #FAFAD2;color: #284775;"> 
      <td> 
       <asp:Button ID="ArchiveButton" runat="server" CommandName="Delete" 
        Text="Archive" /> 
       <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerIdLabel" runat="server" 
        Text='<%# Eval("CustomerId") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerStatusLabel" runat="server" 
        Text='<%# Eval("CustomerStatus") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerFirstNameLabel" runat="server" 
        Text='<%# Eval("CustomerFirstName") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerLastNameLabel" runat="server" 
        Text='<%# Eval("CustomerLastName") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CompanyNameLabel" runat="server" 
        Text='<%# Eval("CompanyName") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerEmailLabel" runat="server" 
        Text='<%# Eval("CustomerEmail") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerTypeLabel" runat="server" 
        Text='<%# Eval("CustomerType") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPhoneNumberLabel" runat="server" 
        Text='<%# Eval("CustomerPhoneNumber") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerSubscriptionTypeLabel" runat="server" 
        Text='<%# Eval("CustomerSubscriptionType") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPaymentMethodLabel" runat="server" 
        Text='<%# Eval("CustomerPaymentMethod") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPickUpDayLabel" runat="server" 
        Text='<%# Eval("CustomerPickUpDay") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPickUpDay2Label" runat="server" 
        Text='<%# Eval("CustomerPickUpDay2") %>' /> 
      </td> 
     </tr> 
    </AlternatingItemTemplate> 
    <EditItemTemplate> 
     <tr style="background-color: #FFCC66;color: #000080;"> 
      <td> 
       <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
        Text="Update" /> 
       <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
        Text="Cancel" /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerIdLabel1" runat="server" 
        Text='<%# Eval("CustomerId") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerStatusTextBox" runat="server" 
        Text='<%# Bind("CustomerStatus") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerFirstNameTextBox" runat="server" 
        Text='<%# Bind("CustomerFirstName") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerLastNameTextBox" runat="server" 
        Text='<%# Bind("CustomerLastName") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CompanyNameTextBox" runat="server" 
        Text='<%# Bind("CompanyName") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerEmailTextBox" runat="server" 
        Text='<%# Bind("CustomerEmail") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerTypeTextBox" runat="server" 
        Text='<%# Bind("CustomerType") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerPhoneNumberTextBox" runat="server" 
        Text='<%# Bind("CustomerPhoneNumber") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerSubscriptionTypeTextBox" runat="server" 
        Text='<%# Bind("CustomerSubscriptionType") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerPaymentMethodTextBox" runat="server" 
        Text='<%# Bind("CustomerPaymentMethod") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerPickUpDayTextBox" runat="server" 
        Text='<%# Bind("CustomerPickUpDay") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerPickUpDay2TextBox" runat="server" 
        Text='<%# Bind("CustomerPickUpDay2") %>' /> 
      </td> 
     </tr> 
    </EditItemTemplate> 
    <EmptyDataTemplate> 
     <table runat="server" 
      style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;"> 
      <tr> 
       <td> 
        No data was returned.</td> 
      </tr> 
     </table> 
    </EmptyDataTemplate> 
    <InsertItemTemplate> 
     <tr style=""> 
      <td> 
       <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
        Text="Insert" /> 
       <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
        Text="Clear" /> 
      </td> 
      <td> 
       &nbsp;</td> 
      <td> 
       <asp:TextBox ID="CustomerStatusTextBox" runat="server" 
        Text='<%# Bind("CustomerStatus") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerFirstNameTextBox" runat="server" 
        Text='<%# Bind("CustomerFirstName") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerLastNameTextBox" runat="server" 
        Text='<%# Bind("CustomerLastName") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CompanyNameTextBox" runat="server" 
        Text='<%# Bind("CompanyName") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerEmailTextBox" runat="server" 
        Text='<%# Bind("CustomerEmail") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerTypeTextBox" runat="server" 
        Text='<%# Bind("CustomerType") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerPhoneNumberTextBox" runat="server" 
        Text='<%# Bind("CustomerPhoneNumber") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerSubscriptionTypeTextBox" runat="server" 
        Text='<%# Bind("CustomerSubscriptionType") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerPaymentMethodTextBox" runat="server" 
        Text='<%# Bind("CustomerPaymentMethod") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerPickUpDayTextBox" runat="server" 
        Text='<%# Bind("CustomerPickUpDay") %>' /> 
      </td> 
      <td> 
       <asp:TextBox ID="CustomerPickUpDay2TextBox" runat="server" 
        Text='<%# Bind("CustomerPickUpDay2") %>' /> 
      </td> 
     </tr> 
    </InsertItemTemplate> 
    <ItemTemplate> 
     <tr style="background-color: #FFFBD6;color: #333333;"> 
      <td> 
       <asp:Button ID="ArchiveButton" runat="server" CommandName="Delete" 
        Text="Archive" /> 
       <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerIdLabel" runat="server" 
        Text='<%# Eval("CustomerId") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerStatusLabel" runat="server" 
        Text='<%# Eval("CustomerStatus") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerFirstNameLabel" runat="server" 
        Text='<%# Eval("CustomerFirstName") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerLastNameLabel" runat="server" 
        Text='<%# Eval("CustomerLastName") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CompanyNameLabel" runat="server" 
        Text='<%# Eval("CompanyName") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerEmailLabel" runat="server" 
        Text='<%# Eval("CustomerEmail") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerTypeLabel" runat="server" 
        Text='<%# Eval("CustomerType") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPhoneNumberLabel" runat="server" 
        Text='<%# Eval("CustomerPhoneNumber") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerSubscriptionTypeLabel" runat="server" 
        Text='<%# Eval("CustomerSubscriptionType") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPaymentMethodLabel" runat="server" 
        Text='<%# Eval("CustomerPaymentMethod") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPickUpDayLabel" runat="server" 
        Text='<%# Eval("CustomerPickUpDay") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPickUpDay2Label" runat="server" 
        Text='<%# Eval("CustomerPickUpDay2") %>' /> 
      </td> 
     </tr> 
    </ItemTemplate> 
    <LayoutTemplate> 
     <table runat="server"> 
      <tr runat="server"> 
       <td runat="server"> 
        <table ID="itemPlaceholderContainer" runat="server" border="1" 
         style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;"> 
         <tr runat="server" style="background-color: #FFFBD6;color: #333333;"> 
          <th runat="server"> 
          </th> 
          <th runat="server"> 
           Id</th> 
          <th runat="server"> 
           Status</th> 
          <th runat="server"> 
           First Name</th> 
          <th runat="server"> 
           Last Name</th> 
          <th runat="server"> 
           Company Name</th> 
          <th runat="server"> 
           E-mail</th> 
          <th runat="server"> 
           Type</th> 
          <th runat="server"> 
           Phone Number</th> 
          <th runat="server"> 
           Subscription Type</th> 
          <th runat="server"> 
           Payment Method</th> 
          <th runat="server"> 
           Pick-Up Day</th> 
          <th runat="server"> 
           Second Pick-Up Day</th> 
         </tr> 
         <tr ID="itemPlaceholder" runat="server"> 
         </tr> 
        </table> 
       </td> 
      </tr> 
      <tr runat="server"> 
       <td runat="server" 
        style="text-align: center;background-color: #FFCC66;font-family: Verdana, Arial, Helvetica, sans-serif;color: #333333;"> 
        <asp:DataPager ID="DataPager1" runat="server"> 
         <Fields> 
          <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
           ShowNextPageButton="False" ShowPreviousPageButton="False" /> 
          <asp:NumericPagerField /> 
          <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" 
           ShowNextPageButton="False" ShowPreviousPageButton="False" /> 
         </Fields> 
        </asp:DataPager> 
       </td> 
      </tr> 
     </table> 
    </LayoutTemplate> 
    <SelectedItemTemplate> 
     <tr style="background-color: #FFCC66;font-weight: bold;color: #000080;"> 
      <td> 
       <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
        Text="Delete" /> 
       <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerIdLabel" runat="server" 
        Text='<%# Eval("CustomerId") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerStatusLabel" runat="server" 
        Text='<%# Eval("CustomerStatus") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerFirstNameLabel" runat="server" 
        Text='<%# Eval("CustomerFirstName") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerLastNameLabel" runat="server" 
        Text='<%# Eval("CustomerLastName") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CompanyNameLabel" runat="server" 
        Text='<%# Eval("CompanyName") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerEmailLabel" runat="server" 
        Text='<%# Eval("CustomerEmail") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerTypeLabel" runat="server" 
        Text='<%# Eval("CustomerType") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPhoneNumberLabel" runat="server" 
        Text='<%# Eval("CustomerPhoneNumber") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerSubscriptionTypeLabel" runat="server" 
        Text='<%# Eval("CustomerSubscriptionType") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPaymentMethodLabel" runat="server" 
        Text='<%# Eval("CustomerPaymentMethod") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPickUpDayLabel" runat="server" 
        Text='<%# Eval("CustomerPickUpDay") %>' /> 
      </td> 
      <td> 
       <asp:Label ID="CustomerPickUpDay2Label" runat="server" 
        Text='<%# Eval("CustomerPickUpDay2") %>' /> 
      </td> 
     </tr> 
    </SelectedItemTemplate> 
</asp:ListView> 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConflictDetection="CompareAllValues" 
    ConnectionString="<%$ ConnectionStrings:tcc_customersConnectionString %>" 
    DeleteCommand="DELETE FROM [Customers] WHERE [CustomerId] = @original_CustomerId AND [CustomerStatus] = @original_CustomerStatus AND [CustomerFirstName] = @original_CustomerFirstName AND [CustomerLastName] = @original_CustomerLastName AND [CompanyName] = @original_CompanyName AND [CustomerEmail] = @original_CustomerEmail AND [CustomerType] = @original_CustomerType AND [CustomerPhoneNumber] = @original_CustomerPhoneNumber AND [CustomerSubscriptionType] = @original_CustomerSubscriptionType AND [CustomerPaymentMethod] = @original_CustomerPaymentMethod AND [CustomerPickUpDay] = @original_CustomerPickUpDay AND [CustomerPickUpDay2] = @original_CustomerPickUpDay2" 
    InsertCommand="INSERT INTO [Customers] ([CustomerStatus], [CustomerFirstName], [CustomerLastName], [CompanyName], [CustomerEmail], [CustomerType], [CustomerPhoneNumber], [CustomerSubscriptionType], [CustomerPaymentMethod], [CustomerPickUpDay], [CustomerPickUpDay2]) VALUES (@CustomerStatus, @CustomerFirstName, @CustomerLastName, @CompanyName, @CustomerEmail, @CustomerType, @CustomerPhoneNumber, @CustomerSubscriptionType, @CustomerPaymentMethod, @CustomerPickUpDay, @CustomerPickUpDay2)" 
    OldValuesParameterFormatString="original_{0}" 
    SelectCommand="SELECT [CustomerId], [CustomerStatus], [CustomerFirstName], [CustomerLastName], [CompanyName], [CustomerEmail], [CustomerType], [CustomerPhoneNumber], [CustomerSubscriptionType], [CustomerPaymentMethod], [CustomerPickUpDay], [CustomerPickUpDay2] FROM [Customers] ORDER BY [CustomerLastName], [CustomerFirstName], [CustomerId]" 
    UpdateCommand="UPDATE [Customers] SET [CustomerStatus] = @CustomerStatus, [CustomerFirstName] = @CustomerFirstName, [CustomerLastName] = @CustomerLastName, [CompanyName] = @CompanyName, [CustomerEmail] = @CustomerEmail, [CustomerType] = @CustomerType, [CustomerPhoneNumber] = @CustomerPhoneNumber, [CustomerSubscriptionType] = @CustomerSubscriptionType, [CustomerPaymentMethod] = @CustomerPaymentMethod, [CustomerPickUpDay] = @CustomerPickUpDay, [CustomerPickUpDay2] = @CustomerPickUpDay2 WHERE [CustomerId] = @original_CustomerId AND [CustomerStatus] = @original_CustomerStatus AND [CustomerFirstName] = @original_CustomerFirstName AND [CustomerLastName] = @original_CustomerLastName AND [CompanyName] = @original_CompanyName AND [CustomerEmail] = @original_CustomerEmail AND [CustomerType] = @original_CustomerType AND [CustomerPhoneNumber] = @original_CustomerPhoneNumber AND [CustomerSubscriptionType] = @original_CustomerSubscriptionType AND [CustomerPaymentMethod] = @original_CustomerPaymentMethod AND [CustomerPickUpDay] = @original_CustomerPickUpDay AND [CustomerPickUpDay2] = @original_CustomerPickUpDay2"> 
    <DeleteParameters> 
     <asp:Parameter Name="original_CustomerId" Type="Int32" /> 
     <asp:Parameter Name="original_CustomerStatus" Type="String" /> 
     <asp:Parameter Name="original_CustomerFirstName" Type="String" /> 
     <asp:Parameter Name="original_CustomerLastName" Type="String" /> 
     <asp:Parameter Name="original_CompanyName" Type="String" /> 
     <asp:Parameter Name="original_CustomerEmail" Type="String" /> 
     <asp:Parameter Name="original_CustomerType" Type="String" /> 
     <asp:Parameter Name="original_CustomerPhoneNumber" Type="String" /> 
     <asp:Parameter Name="original_CustomerSubscriptionType" Type="String" /> 
     <asp:Parameter Name="original_CustomerPaymentMethod" Type="String" /> 
     <asp:Parameter Name="original_CustomerPickUpDay" Type="String" /> 
     <asp:Parameter Name="original_CustomerPickUpDay2" Type="String" /> 
    </DeleteParameters> 
    <InsertParameters> 
     <asp:Parameter Name="CustomerStatus" Type="String" /> 
     <asp:Parameter Name="CustomerFirstName" Type="String" /> 
     <asp:Parameter Name="CustomerLastName" Type="String" /> 
     <asp:Parameter Name="CompanyName" Type="String" /> 
     <asp:Parameter Name="CustomerEmail" Type="String" /> 
     <asp:Parameter Name="CustomerType" Type="String" /> 
     <asp:Parameter Name="CustomerPhoneNumber" Type="String" /> 
     <asp:Parameter Name="CustomerSubscriptionType" Type="String" /> 
     <asp:Parameter Name="CustomerPaymentMethod" Type="String" /> 
     <asp:Parameter Name="CustomerPickUpDay" Type="String" /> 
     <asp:Parameter Name="CustomerPickUpDay2" Type="String" /> 
    </InsertParameters> 
    <UpdateParameters> 
     <asp:Parameter Name="CustomerStatus" Type="String" /> 
     <asp:Parameter Name="CustomerFirstName" Type="String" /> 
     <asp:Parameter Name="CustomerLastName" Type="String" /> 
     <asp:Parameter Name="CompanyName" Type="String" /> 
     <asp:Parameter Name="CustomerEmail" Type="String" /> 
     <asp:Parameter Name="CustomerType" Type="String" /> 
     <asp:Parameter Name="CustomerPhoneNumber" Type="String" /> 
     <asp:Parameter Name="CustomerSubscriptionType" Type="String" /> 
     <asp:Parameter Name="CustomerPaymentMethod" Type="String" /> 
     <asp:Parameter Name="CustomerPickUpDay" Type="String" /> 
     <asp:Parameter Name="CustomerPickUpDay2" Type="String" /> 
     <asp:Parameter Name="original_CustomerId" Type="Int32" /> 
     <asp:Parameter Name="original_CustomerStatus" Type="String" /> 
     <asp:Parameter Name="original_CustomerFirstName" Type="String" /> 
     <asp:Parameter Name="original_CustomerLastName" Type="String" /> 
     <asp:Parameter Name="original_CompanyName" Type="String" /> 
     <asp:Parameter Name="original_CustomerEmail" Type="String" /> 
     <asp:Parameter Name="original_CustomerType" Type="String" /> 
     <asp:Parameter Name="original_CustomerPhoneNumber" Type="String" /> 
     <asp:Parameter Name="original_CustomerSubscriptionType" Type="String" /> 
     <asp:Parameter Name="original_CustomerPaymentMethod" Type="String" /> 
     <asp:Parameter Name="original_CustomerPickUpDay" Type="String" /> 
     <asp:Parameter Name="original_CustomerPickUpDay2" Type="String" /> 
    </UpdateParameters> 
</asp:SqlDataSource> 

, а затем в файле отделенного кода У меня есть

protected void ArchiveBeforeDelete(object sender, ListViewDeleteEventArgs e) 
    { 
     int listIndex = (int)e.ItemIndex; 
    } 

Вот и все у меня есть, что получает индекс. И тогда я пробовал такие вещи, как @ itsme86, но все это безрезультатно ... Все, что я действительно хочу, это CustomerID, чтобы затем я мог вызвать этот конкретный идентификатор из таблицы, а затем вставить в другой, заархивированных клиентов table ...

+0

Это должен быть один из подэлементов: ListViewItem.SubItems [index] .Text – itsme86

+0

Не могли бы вы предоставить более полный пример кода? – Jake1164

+0

@ itsme86 Я пробовал это, но .Text не работает, я смотрел на другой вопрос о вопросе stackoverflow, и у него было это, но это была winform, это веб-приложение, возможно, я должен был указать, дайте мне посмотреть, что код Я могу вам помочь, что может быть полезно – cb1295

ответ

0

Итак, как я предложил в предыдущем комментарии, можно редактировать DeleteCommand на странице .aspx следующим образом:

INSERT INTO ArchivedCustomers SELECT CustomerStatus, CustomerGroup, CustomerFirstName, CustomerLastName, CompanyName, CustomerAddress, CustomerCity, CustomerState, CustomerZipcode, CustomerEmail, CustomerEmail2, CustomerPhoneNumber, CustomerPhoneNumberExt, CustomerType, CustomerSubscriptionType, CustomerCost, CustomerPaymentMethod, CustomerSignUpDate, CustomerPickUpDay, CustomerPickUpDay2, CustomerNotes FROM Customers WHERE CustomerID = @original_CustomerID; DELETE FROM Customers WHERE CustomerId = @original_CustomerId" 

Как вы можете видеть, первые он вставляется в таблицу ArchivedCustomers и ТОГДА удаляется ocne. Я покончил с этим. Одно дело отметить, однако, мне пришлось изменить свойство ConflictDetection из CompareAllValues ​​на OverwriteChanges, чтобы не допустить получения ошибки. Если кто-то хочет объяснить, пожалуйста, сделайте это, но на данный момент все, что мне нужно, это то, что ЭТО РАБОТАЕТ! :) Большое спасибо @ Jake1164, если бы вы не заставили меня опубликовать этот код, я не думаю, что увидела бы возможность редактировать эту команду так же быстро, как и я.

1

Вы должны поместить CustomerId в тег «tr», чтобы вы могли вернуть его в обработчик событий. Смотрите ниже ...

<asp:ListView ID="ListView1" runat="server" DataKeyNames="CustomerId" 
DataSourceID="SqlDataSource1" OnItemDeleting= "ArchiveBeforeDelete"> 
<AlternatingItemTemplate> 
    <tr id="<%# Eval("CustomerId") %>" 
     style="background-color: #FAFAD2;color: #284775;"> 
     <td> 
      <asp:Button ID="ArchiveButton" runat="server" CommandName="Delete" 
       Text="Archive" /> 
      <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> 
     </td> 
     <td> 
      <asp:Label ID="CustomerIdLabel" runat="server" 
       Text='<%# Eval("CustomerId") %>' /> 
     </td> 
     <td> 
      <asp:Label ID="CustomerStatusLabel" runat="server" 
       Text='<%# Eval("CustomerStatus") %>' /> 
     </td> 
etc. 
+0

Это может сработать, не уверен, найти мое собственное решение, на которое я намекнул в комментариях, опубликует его через секунду. В любом случае спасибо! – cb1295