Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Data » Downloads
Add your own
alternative version

ObjectDataSource In Depth

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataKeyNames="Id" DataSourceID="ObjectDataSource1" EnableSortingAndPagingCallbacks="True" PageSize="4">
                <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" />
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
            DeleteMethod="Delete" InsertMethod="Add" OldValuesParameterFormatString="old_{0}"
            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">
        <br />
        <table border="0">
                <td style="width: 100px">
                <td style="width: 100px">
                    <asp:TextBox ID="txtName" runat="server" EnableViewState="False"></asp:TextBox></td>
                <td style="width: 100px">
                <td style="width: 100px">
                    <asp:TextBox ID="txtDescription" runat="server" EnableViewState="False"></asp:TextBox></td>
                <td style="width: 100px">
                <td style="width: 100px">
                    <asp:TextBox ID="txtPrice" runat="server" EnableViewState="False"></asp:TextBox></td>
        <asp:LinkButton ID="lbAdd" runat="server" OnClick="lbAdd_Click">Add Product</asp:LinkButton><br />
        <br />
        <asp:Label ID="lbResult" runat="server" EnableViewState="False"></asp:Label>

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.


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


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 (
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 ( for some years (and continues to do so eventually).

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