Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Web Pages with WebMatrix
This is the forum to discuss the Wrox book Beginning ASP.NET Web Pages with WebMatrix by Mike Brind, Imar Spaanjaars ; ISBN: 978-1-1180-5048-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Web Pages with WebMatrix section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2012, 01:39 PM
Authorized User
 
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default Chapter 11:Bulk Deleting

Hi
When running Deletcategories in firefox I get the following message in firebug: i don't see anything wrong. Please help. Thanks.

"$ is not defined
[Break On This Error]

$(function(){
"

my code:
Code:
@{
    var message="";
    var sql="";
    var db = Database.Open("Classifieds");
    
    if(!Request["categoryId"].IsEmpty()){
        sql="DELETE FROM Categories WHERE CategoryId IN ({0})";
        try{
            db.ExecuteIn(sql, Request["categoryId"]);
            message="Categories Deleted. Delete more?";
        }
        catch(Exception ex){
            message="One or more Categories could not be deleted. Other references exist";
        }
    }
    sql="SELECT * FROM Categories";
    var categories =db.Query(sql);
}
<script type ="text/javascript">
    $(function(){
        $('#delete').click(function(){
            return confirm('Are you sure you want to delete?');
        });
    });
</script>
<form method="post">
    <fieldset>
        <legend>Delete Categories</legend>
        <div>@message</div>
        <div>
            Select Categories to delete:
            <div>
                @foreach(var cat in categories){
                    <input type="checkbox" name="categoryId" value="@cat.CategoryId" />@cat.Category<br />
                }
            </div>
            <input type="submit" id="delete" value="Delete" />
        </div>
    </fieldset>
</form>
 
Old January 23rd, 2012, 02:59 PM
Wrox Author
 
Join Date: Dec 2011
Posts: 57
Thanks: 1
Thanked 19 Times in 19 Posts
Default

That means that you have not referenced jQuery in _AdminLayout.cshtml, which is shown in step 2 of the Try It Out:

Quote:
2. Amend _AdminLayout.cshtml to include a link to this new file, and a reference to jQuery with the addition of the highlighted code below:

Code:
<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <link href="@Href("~/Content/StyleSheet.css")" rel="stylesheet" type="text/css" />
        <script src="@Href("~/Scripts/jquery-1.5.min.js")" type="text/javascript"></script>
    </head>
    <body>
        <div id="content">
            <h1>Admin</h1>
            <a href="@Href("~/Admin/CreateCategory")">Create Category</a> 
            | 
            <a href="@Href("~/Admin/UpdateCategory")">Update Category</a>
            | 
            <a href="@Href("~/Admin/DeleteCategory")">Delete Category</a>
            | 
            <a href="@Href("~/Admin/DeleteCategories")">Delete Categories</a>
            <hr />
            @RenderBody()
        </div>
    </body>
</html>
 
Old January 24th, 2012, 10:06 AM
Authorized User
 
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Thanks Mike, it works now.

I have a question regarding deleting items from a database. Is there way to make an item deleted to the user but not really deleted in the database? I was thinking if there was like a 0 or 1 where 0 is deleted and 1 is not deleted. Also if its 0 its not visible to the end user.

Thanks.
 
Old January 24th, 2012, 03:46 PM
Wrox Author
 
Join Date: Dec 2011
Posts: 57
Thanks: 1
Thanked 19 Times in 19 Posts
Default

That approach is called a logical delete (as opposed to a physical delete). It's mentioned in Chapter 10 (p 258). You use UPDATE statements instead of DELETE statements.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10: Deleting rows from a table stevedm BOOK: Beginning iPad Application Development 8 September 27th, 2010 02:21 PM
Chapter 3 - Bulk Insert Example Problem. AP BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 4 February 5th, 2009 04:50 PM
chapter 11 figure 11-7 relative positioning pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 November 29th, 2007 06:11 AM
chapter 6 deleting a record problem mustafa BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 November 6th, 2006 12:08 PM
Deleting a Record pg. 178 Chapter 6 Mantis_Atlantis BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 March 13th, 2006 02:26 PM





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