Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 ContextTypeName Property
.NET Framework Class Library
LinqDataSource..::.ContextTypeName Property

Updated: November 2007

Gets or sets the name of the type that contains the property whose value has the data that you want to retrieve.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

Visual Basic (Declaration)
Public Property ContextTypeName As String
Visual Basic (Usage)
Dim instance As LinqDataSource
Dim value As String

value = instance.ContextTypeName

instance.ContextTypeName = value
C#
public string ContextTypeName { get; set; }
Visual C++
public:
property String^ ContextTypeName {
    String^ get ();
    void set (String^ value);
}
J#
/** @property */
public String get_ContextTypeName()
/** @property */
public  void set_ContextTypeName(String value)
JScript
public function get ContextTypeName () : String
public function set ContextTypeName (value : String)
ASP.NET
<asp:LinqDataSource ContextTypeName="String" />

Property Value

Type: System..::.String

The name of the class to retrieve data from.

When you use the LinqDataSource control to retrieve data from either an in-memory data collection or a database, you must specify two properties. The first is a data context class that represents the data source. The second is a property in the data context class that contains the data. You set the ContextTypeName property to the name of the data context class and you set the TableName property to the data collection that contains the data.

For example, when you retrieve data from a database, set the ContextTypeName property to the name of the class that represents the database. Also set the TableName property to the property that represents the table in the database. To generate classes from a database, use the O/R Designer or the SqlMetal.exe utility to automatically generate those classes.

When you retrieve data from an in-memory data collection such as an array, set the ContextTypeName property to the name of the class that contains the array property. Then set the TableName property to the property that gets the array.

To enable automatic update, insert, or delete operations through the LinqDataSource control, the class assigned to the ContextTypeName property must derive from DataContext. In addition, the property assigned to the TableName property must derive from Table<(Of <(TEntity>)>). If you do not need to enable automatic update, insert, or delete operations, you can assign the name of any type of class to the ContextTypeName property.

For information about how to select data from an instance of a class, see the Result property.

The following example shows how to set the ContextTypeName property to a class that contains an array of strings. It also shows how to set the property to a class (generated by the O/R Designer) that represents a database.

Visual Basic
<!-- Retrieve and display data from array of string values -->
<asp:LinqDataSource 
    ContextTypeName="MovieLibrary" 
    TableName="AvailableGenres" 
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>
<asp:DropDownList 
    DataSourceID="LinqDataSource1"
    runat="server" 
    ID="DropDownList1">
</asp:DropDownList>

<!-- Retrieve and display data from database -->
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Movies" 
    Select="Title"
    ID="LinqDataSource2" 
    runat="server">
</asp:LinqDataSource>
<asp:DropDownList 
    DataSourceID="LinqDataSource2"
    runat="server" 
    ID="DropDownList2">
</asp:DropDownList>

C#
<!-- Retrieve and display data from array of string values -->
<asp:LinqDataSource 
    ContextTypeName="MovieLibrary" 
    TableName="AvailableGenres" 
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>
<asp:DropDownList 
    DataSourceID="LinqDataSource1"
    runat="server" 
    ID="DropDownList1">
</asp:DropDownList>

<!-- Retrieve and display data from database -->
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Movies" 
    Select="Title"
    ID="LinqDataSource2" 
    runat="server">
</asp:LinqDataSource>
<asp:DropDownList 
    DataSourceID="LinqDataSource2"
    runat="server" 
    ID="DropDownList2">
</asp:DropDownList>

The class named ExampleDataContext that represents the database table is not shown in this example. For this example to work, you must create this class by adding a LINQ To SQL class named Example.dbml and dragging a table named Movie onto the O/R Designer. A class named ExampleDataContext with a property named Movies is generated.

The following example shows the class named MovieLibrary that is referenced in the LinqDataSource control.

Visual Basic
Public Class MovieLibrary
    Dim _availableGenres() As String = {"Comedy", "Drama", "Romance"}

    Public ReadOnly Property AvailableGenres() As String()
        Get
            Return _availableGenres
        End Get
    End Property

End Class

C#
public class MovieLibrary
{
    string[] _availableGenres = { "Comedy", "Drama", "Romance" };

    public MovieLibrary()
    {
    }

    public string[] AvailableGenres
    {
        get
        {
            return _availableGenres;
        }
    }
}

Windows Vista, Windows XP SP2, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker