Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 18th, 2008, 07:57 AM
Authorized User
Join Date: Apr 2008
Location: , , .
Posts: 25
Thanks: 0
Thanked 1 Time in 1 Post
Default How to enable deleting in DetailsView?

Hi! I am trying to create a delete function in DetailsView. I have already set up an SqlDataSource, generated Insert, Update and Delete statements in that SqlDataSource, clicked on Enable Deleting, Editing and Inserting in the DetailsView Taskbar. The table also has a primary key. But the Delete link does not appear. Here is the ASP code:

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1" DefaultMode="Insert" 
            Height="50px" Width="731px" AutoGenerateDeleteButton="True">
                <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" 
                    InsertVisible="False" ReadOnly="True" SortExpression="EmployeeID" />
                <asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
ID="RequiredFieldValidator1" ControlToValidate="TextBox1" 
runat="server" ErrorMessage="Please enter your first 

<%-- Code truncated --%>

                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                    ShowInsertButton="True" ShowSelectButton="True" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:nexConnectionString %>" 
            DeleteCommand="DELETE FROM [Employees] WHERE [EmployeeID] = @EmployeeID" 
            InsertCommand="INSERT INTO [Employees] ([LastName],
 [FirstName], [Designation], [Address], [City], [Telephone], 
[Birthdate], [DepartmentID], [Email]) VALUES (@LastName, @FirstName, 
@Designation, @Address, @City, @Telephone, @Birthdate, @DepartmentID, 
            SelectCommand="SELECT * FROM [Employees] WHERE ([EmployeeID] = @EmployeeID)" 

            UpdateCommand="UPDATE [Employees] SET [LastName] = @LastName, 
[FirstName] = @FirstName, [Designation] = @Designation, [Address] = 
@Address, [City] = @City, [Telephone] = @Telephone, [Birthdate] = 
@Birthdate, [DepartmentID] = @DepartmentID, [Email] = @Email WHERE 
[EmployeeID] = @EmployeeID">
                <asp:QueryStringParameter Name="EmployeeID" QueryStringField="EmployeeID" 
                    Type="Int32" />
                <asp:Parameter Name="EmployeeID" Type="Int32" />
                <asp:Parameter Name="LastName" Type="String" />
<%-- Code Truncated --%>
          <asp:Parameter Name="Email" Type="String" />
Thanks for your help.
  #2 (permalink)  
Old June 18th, 2008, 10:51 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Hi there,

Take a look at this:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
  DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1" DefaultMode="Insert"
  Height="50px" Width="731px" AutoGenerateDeleteButton="True">
  Notice how you've set the mode to Insert. When the DetailsView is in Insert mode, there is nothing to delete. Remove the attribute, and the Delete link is back.

Alternatively, use its ChangeMode method to switch the control in the relevant method.

Hope this helps


Imar Spaanjaars
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable Property kekec3778 Beginning VB 6 2 January 8th, 2008 06:32 AM
Enable Update and Enable Delete check boxes don't mihabib ASP.NET 2.0 Basics 2 December 7th, 2006 11:44 AM
DetailsView faithfulman ASP.NET 2.0 Basics 1 September 22nd, 2006 11:16 PM
Enable - Macros alannoble26 Excel VBA 2 November 28th, 2005 09:08 AM
Enable Assertions ssmith71 BOOK: Beginning Java 2, JDK 5 Edition 0 June 3rd, 2005 12:03 PM

All times are GMT -4. The time now is 02:17 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.