ASP.NET
  Home arrow ASP.NET arrow Source Code for Saving and Retrieving Data...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Source Code for Saving and Retrieving Data with AJAX
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating:  stars stars stars stars stars / 0
    2008-09-11

    Table of Contents:
  • Source Code for Saving and Retrieving Data with AJAX
  • More Source Code Listings
  • Still More Source Code Listings
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Source Code for Saving and Retrieving Data with AJAX


    (Page 1 of 4 )

    In this conclusion to a four-part series on making your ASP.NET applications with AJAX save and retrieve data, we list the source code for the applications covered, summarize what you've learned, and give you some exercises to test your skill. This article is excerpted from chapter four of Learning ASP.NET 2.0 with AJAX: A Practical Hands-on Guide, written by Jesse Liberty, Dan Hurwitz and Brian MacDonald (O'Reilly, 2007; ISBN: 0596513976). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

    Source Code Listings

    The complete markup for the Default.aspx file in the AWProductData site is shown in Example 4-5 , with the code-behind shown directly after in Example 4-6.


    Figure 4-26.  When you selected a product in the first grid, the order details appear below in the second grid.

    Example 4-5. Default.aspx for AWProductData

    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb"
        Inherits="_Default" %>

    <!DOCTYPE html public "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
       
    <title>Untitled Page</title>
    </head>
    <body>
       
    <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
            &nbsp;&nbsp;
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString=
                    "<%$ ConnectionStrings:AdventureWorksConnectionString %>"
                SelectCommand="SELECT [ProductID], [Name], [ProductNumber], [MakeFlag],
                    [SafetyStockLevel], [ReorderPoint] FROM [Production].[Product]"
                DeleteCommand="DELETE FROM [Production].[Product]
                   
    WHERE [ProductID] = @original_ProductID AND [Name] = @original_Name
                        AND [ProductNumber] = @original_ProductNumber
                        AND [MakeFlag] = @original_MakeFlag
                        AND [SafetyStockLevel] = @original_SafetyStockLevel
                        AND [ReorderPoint] = @original_ReorderPoint"
               
    InsertCommand="INSERT INTO [Production].[Product] ([Name],
                    [ProductNumber], [MakeFlag], [SafetyStockLevel], [ReorderPoint])
                    VALUES (@Name, @ProductNumber, @MakeFlag, @SafetyStockLevel,
                       
    @ReorderPoint)"
                UpdateCommand="UPDATE [Production].[Product]
                       
    SET [Name] = @Name, [ProductNumber] = @ProductNumber,
                         [MakeFlag] = @MakeFlag,
                         [SafetyStockLevel] = @SafetyStockLevel,
                         [ReorderPoint] = @ReorderPoint
                   
    WHERE [ProductID] = @original_ProductID
                        AND [Name] = @original_Name
                        AND [ProductNumber] = @original_ProductNumber
                        AND [MakeFlag] = @original_MakeFlag
                        AND [SafetyStockLevel] = @original_SafetyStockLevel
                        AND [ReorderPoint] = @original_ReorderPoint"

                ConflictDetection= "CompareAllValues" 
       OldValuesParameterFormatString="original_{0}" >
                <DeleteParameters>
                   
    <asp:Parameter Name="original_ProductID" Type="Int32" />
                    <asp:Parameter Name="original_Name" Type="String" />
                    <asp:Parameter Name="original_ProductNumber" Type="String" />
                    <asp:Parameter Name="original_MakeFlag" Type="Boolean" />
                    <asp:Parameter Name="original_SafetyStockLevel" Type="Int16" />
                    <asp:Parameter Name="original_ReorderPoint" Type="Int16" />
                </DeleteParameters>
               
    <UpdateParameters>
                    <asp:Parameter Name="Name" Type="String" />
                    <asp:Parameter Name="ProductNumber" Type="String" />
                    <asp:Parameter Name="MakeFlag" Type="Boolean" />
                    <asp:Parameter Name="SafetyStockLevel" Type="Int16" />
                    <asp:Parameter Name="ReorderPoint" Type="Int16" />
                    <asp:Parameter Name="original_ProductID" Type="Int32" />
                    <asp:Parameter Name="original_Name" Type="String" />
                    <asp:Parameter Name="original_ProductNumber" Type="String" />
                    <asp:Parameter Name="original_MakeFlag" Type="Boolean" />
                    <asp:Parameter Name="original_SafetyStockLevel" Type="Int16" />
                    <asp:Parameter Name="original_ReorderPoint" Type="Int16" />
                </UpdateParameters>
               
    <InsertParameters>
                    <asp:Parameter Name="Name" Type="String" />
                    <asp:Parameter Name="ProductNumber" Type="String" />
                    <asp:Parameter Name="MakeFlag" Type="Boolean" />
                    <asp:Parameter Name="SafetyStockLevel" Type="Int16" />
                    <asp:Parameter Name="ReorderPoint" Type="Int16" />
                </InsertParameters>
            </asp:SqlDataSource>
                   
    <asp:GridView ID="GridView1" runat="server"
                        AllowPaging="True" AllowSorting="True" 
                     AutoGenerateColumns="False"
                        DataKeyNames="ProductID" DataSourceID="SqlDataSource1"
                        BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
                        BorderWidth="1px" CellPadding="3" CellSpacing="2"
                        OnRowDataBound= "GridView1_RowDataBound"
                        OnSelectedIndexChanged= "GridView1_SelectedIndexChanged">
                        <Columns>
                           
    <asp:CommandField ButtonType="Button"
                         ShowDeleteButton="True"
    ShowEditButton="True" />
                            
    <asp:BoundField DataField="ProductID" HeaderText="ID" 
                           InsertVisible="False"
                                 ReadOnly="True" SortExpression="ProductID" />
                           
    <asp:BoundField DataField="Name" HeaderText="Name"
                         SortExpression="Name" />
                           
    <asp:BoundField DataField="ProductNumber" 
                       HeaderText="ProductNumber"
               SortExpression="ProductNumber" />
                           
    <asp:CheckBoxField DataField="MakeFlag"
                           HeaderText="MakeFlag" SortExpression="MakeFlag" />
                           
    <asp:BoundField DataField="SafetyStockLevel" 
                   HeaderText="SafetyStockLevel"
            SortExpression="SafetyStockLevel" />
                           
    <asp:BoundField DataField="ReorderPoint" 
                       HeaderText="ReorderPoint"
                 SortExpression="ReorderPoint" />
                        </Columns>
                        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
                        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True"
                            ForeColor="White" />
                        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#A55129" Font-Bold="True"
                            
    ForeColor="White" />
                    </asp:GridView>
                    <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                </ContentTemplate>
            </asp:UpdatePanel>
        </form>
    </body>
    </html>

    More ASP.NET Articles
    More By O'Reilly Media


     

    Buy this book now. This article is excerpted from chapter four of Learning ASP.NET 2.0 with AJAX: A Practical Hands-on Guide, written by Jesse Liberty, Dan Hurwitz and Brian MacDonald (O'Reilly, 2007; ISBN: 0596513976). Check it out today at your favorite bookstore. Buy this book now.

    ASP.NET ARTICLES

    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT