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

Complex Parameter Support for ObjectDataSource

Rate me:
Please Sign up or sign in to vote.
4.64/5 (6 votes)
3 Feb 2009CPOL2 min read 40.4K   310   26  
An example showing how to create a custom parameter for ASP.NET data sources that allows the passing of arbitrarily complex objects.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CobaltSoftware.TestWebApplication._Default" Trace="true" %>
<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Search Parameters</h1>
        Forename: <asp:TextBox ID="TxtForename" runat="server" Text="Joe" /><br />
        Surname: <asp:TextBox ID="TxtSurname" runat="server" Text="Blogs" /><br />
        Min Age: <asp:TextBox ID="TxtAge" runat="server"  Text="24" /><br />
        <asp:Button ID="BttnClicky" runat="server" Text="Clicky" />
        <br />
        
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="SearchEntities" 
            TypeName="CobaltSoftware.ExampleBusinessLayer.SomedataObject, CobaltSoftware.ExampleBusinessLayer">
            <SelectParameters>
                <Cobalt:ObjectParameter Name="input" TypeName="CobaltSoftware.ExampleBusinessLayer.SearchParametersEntity, CobaltSoftware.ExampleBusinessLayer" >
                    <Properties>
                        <asp:ControlParameter ControlID="TxtForename" name="Forename" />
                        <asp:ControlParameter ControlID="TxtSurname" name="Surname" />
                        <asp:ControlParameter ControlID="TxtAge" name="MinAge" />                        
                    </Properties>
                </Cobalt:ObjectParameter>
            </SelectParameters>
        </asp:ObjectDataSource>
        
        <asp:Repeater ID="RptResult" runat="server" DataSourceID="ObjectDataSource1">
            <HeaderTemplate>
                <h1>Some Example Results</h1>
                <ul>
            </HeaderTemplate>
            <ItemTemplate>
                <li><%# Container.DataItem.ToString() %></li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>
    
    </div>
    </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)


Written By
Software Developer (Senior) Insurance Industry
United Kingdom United Kingdom
Steve Gray is a Senior Developer at a British insurance company, working on a popular aggregator. When he's not writing ASP .NET, it's because there's SQL or WCF to write instead.

Comments and Discussions