Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8836865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:35:23+00:00 2026-06-14T09:35:23+00:00

On an ASP.Net / VB.Net DetailsView that allows inserts, edits, and deletes we would

  • 0

On an ASP.Net / VB.Net DetailsView that allows inserts, edits, and deletes we would like to trap the event that occurs when a user clicks on the Edit button and the Update button of the DetailsView.

We are looking to trap these events with and event handler inside a VB.Net code-behind file.

Can you tell me with sample code how to do it?

* Update *

I tried this coding but get the following error when clicking on the Edit button:

Unable to cast object of type 'System.Web.UI.WebControls.DetailsView' 
to type 'System.Web.UI.WebControls.DetailsViewRow'.

This is the coding from the markup showing the Edit button:

<asp:DetailsView 
    ID="DetailsViewDetails" 
    runat="server" 
    AutoGenerateRows="False" 
    Height="50px" 
    Width="268px" 
    DataSourceID="SqlDataSourceDetails"
    DataKeyNames="ID"
    OnItemCommand="DetailsViewDetails_ItemCommand">

    <Fields>
        <asp:TemplateField ShowHeader="False">

            <EditItemTemplate>
                <asp:Button ID="ButtonUpdate" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update"  />
                &nbsp;<asp:Button ID="ButtonCancelUpdate" runat="server" CausesValidation="False" 
                    CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>

            <InsertItemTemplate>
                <asp:Button ID="ButtonInsert" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:Button ID="ButtonCancelInsert" runat="server" CausesValidation="False" 
                    CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>

            <ItemTemplate>
                <asp:Button ID="ButtonEdit" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit" />
                &nbsp;<asp:Button ID="ButtonNew" runat="server" CausesValidation="False" 
                    CommandName="New" Text="New" />
                &nbsp;<asp:Button ID="ButtonDelete" runat="server" CausesValidation="False" 
                    CommandName="Delete" Text="Delete" />

                    <AjaxToolKit:ConfirmButtonExtender ID="deleteButtonConfirmation" 
                        runat="server" 
                        ConfirmText='<%# "You are about to remove: " & vbcr & 
                            Eval("Forename") & vbcr & Eval("Surname") & "!!!" &
                            vbcrlf & "Are you sure you want to do this?" & vbcrlf &
                            "Clicking the OK button will delete this parent." %>'
                        Enabled="True" 
                        TargetControlID="ButtonDelete">

                    </AjaxToolKit:ConfirmButtonExtender>
            </ItemTemplate>
        </asp:TemplateField>

This is the handler in the code-behind file:

Protected Sub DetailsViewDetails_ItemCommand(sender As Object, e As System.Web.UI.WebControls.DetailsViewCommandEventArgs)
    Dim row As DetailsViewRow = DirectCast(DirectCast(e.CommandSource, Control).NamingContainer, DetailsViewRow)

    Select Case e.CommandName
        Case "Add"

        Case "Edit"
            ' Do this when going into edit mode so changes to the panent's tuition total balance can be updated.
            '---------------------------------------------------------------------------------------------------
            dcmOriginalRegistrationFee = GetValueFromTextBoxRegistrationFee()

        Case "Delete"

    End Select
End Sub

We get the error on the Dim statement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:35:24+00:00Added an answer on June 14, 2026 at 9:35 am

    You can use it’s ItemCommand event with an appropriate CommandName:

    <asp:DetailsView ID="DetailsView1" runat="server"  
        OnItemCommand="DetailsView1_ItemCommand" 
        <Fields>
           <asp:BoundField  DataField="IdField" HeaderText="ID" />
           <asp:BoundField  DataField="NameField" HeaderText="Name" />
           <asp:ButtonField CommandName="Add" Text="Add Something" />
           <asp:ButtonField CommandName="Edit" Text="EditSomething" />
           <asp:ButtonField CommandName="Delete" Text="Delete Something" />
        </Fields>
    </asp:DetailsView>
    

    in codebehind:

    Protected Sub DetailsView1_ItemCommand(sender As Object, e As System.Web.UI.WebControls.DetailsViewCommandEventArgs)
        Select Case e.CommandName
            Case "Add"
    
            Case "Edit"
    
            Case "Delete"
    
        End Select
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used the ASP.NET DetailsView across my application. I would like to know how
In my asp.net MVC 3 project I would like to create a contact that's
ASP.Net 3.5 I want to create a user control that contains the ListView and
When I localize an asp.net page that is using bound controls (DetailsView, etc) that
I currently have a DetailsView in ASP.NET that gets data from the database based
.NET 4 ASP.NET I have a DetailsView that is displaying an entity framework record
I have a asp.net detailsview control on a page. I've noticed that it always
Say you have something like an ASP.NET ASP:DetailsView to show and edit a single
ASP.NET MVC 2 will support validation based on DataAnnotation attributes like this: public class
I have the following detailsview in my asp.net web application. What it should show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.