Click here to Skip to main content
12,401,158 members (30,489 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Data » Downloads

Stats

230.5K views
3.5K downloads
203 bookmarked
Posted

ObjectDataSource In Depth

, 22 Mar 2006 CPOL
An article to master the ObjectDataSource.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomObjectOC.aspx.cs" Inherits="CustomObjectOC" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataKeyNames="Id" DataSourceID="ObjectDataSource1" PageSize="4">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
            </Columns>
        </asp:GridView>
    </div>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="Product"
            DeleteMethod="DeleteOC" InsertMethod="Add" OldValuesParameterFormatString="old_{0}" ConflictDetection="CompareAllValues"
            SelectMethod="LoadAll" TypeName="ProductsDAL" UpdateMethod="Edit" 
            OnDeleted="ObjectDataSource1_Deleted" OnInserted="ObjectDataSource1_Inserted" OnSelected="ObjectDataSource1_Selected" OnUpdated="ObjectDataSource1_Updated" MaximumRowsParameterName="maxRows" StartRowIndexParameterName="startIndex" EnablePaging="true" SelectCountMethod="CountAll" SortParameterName="sortedBy">
        </asp:ObjectDataSource>
        <br />
         <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id"
             DataSourceID="ObjectDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
             <Fields>
                 <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                 <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                 <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                 <asp:CommandField ShowInsertButton="True" />
             </Fields>
         </asp:DetailsView>
        <br />
        <asp:Label ID="lbResult" runat="server" EnableViewState="False"></asp:Label>
       </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Manuel Abadia
Web Developer
Spain Spain
Manuel Abadia had his MS Degree in Computer Science (Univ. Murcia, Spain)

He is a Freelance Software Architect/Engineer and Trainer.

He sells his own components in his webpage (http://www.manuelabadia.com).

He was the Software Architect for the MoviTAP project that won the first prize in the Microsoft and Vodafone mobile web Services contest.

He has done some external work in companies like Namco America Inc. and Gaelco SA.

He has contributed to the MAME project (http://www.mamedev.com) for some years (and continues to do so eventually).

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160721.1 | Last Updated 22 Mar 2006
Article Copyright 2006 by Manuel Abadia
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid