Click here to Skip to main content
15,881,938 members
Articles / Web Development / ASP.NET

GridView ObjectDataSource Adapter

Rate me:
Please Sign up or sign in to vote.
3.67/5 (6 votes)
2 Feb 20073 min read 58.6K   319   29  
In this brief article, the author mentions two techniques that he uses to allow for mapping GridViews to DataTables that are built upon existing middle tier objects.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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 style="text-transform: uppercase; color: blue; text-decoration: underline">
    <form id="form1" runat="server">
    <div style="text-transform: uppercase; color: blue; text-decoration: underline">
 <asp:ObjectDataSource ID="objDataSource" runat="server" SelectMethod="GetEmployees"   TypeName="EmployeeController"></asp:ObjectDataSource>
       
        <asp:ObjectDataSource ID="dataTableSource" runat="server" SelectMethod="GetEmployeesAsTable" TypeName="EmployeeController" ></asp:ObjectDataSource>
        <br />
        This Grid Will Not Support Paging<br />
    
    </div>
        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" DataSourceID="objDataSource" AllowPaging="True" AllowSorting="True" PageSize="2">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
            </Columns>
        </asp:GridView>
        <br />
        <br />
        This Grid Will Support Paging, Sorting<br />
        <br />
        <asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" DataSourceID="dataTableSource" AllowPaging="True" AllowSorting="True" PageSize="2">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
            </Columns>
        </asp:GridView>
    </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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions