LinqDataSourceSelectEventArgs Class (System.Web.UI.WebControls)

Switch View :
ScriptFree
.NET Framework Class Library
LinqDataSourceSelectEventArgs Class

Provides data for the Selecting event.

Inheritance Hierarchy

System.Object
  System.EventArgs
    System.ComponentModel.CancelEventArgs
      System.Web.UI.WebControls.LinqDataSourceSelectEventArgs

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

Visual Basic
Public Class LinqDataSourceSelectEventArgs _
	Inherits CancelEventArgs
C#
public class LinqDataSourceSelectEventArgs : CancelEventArgs
Visual C++
public ref class LinqDataSourceSelectEventArgs : public CancelEventArgs
F#
type LinqDataSourceSelectEventArgs =  
    class
        inherit CancelEventArgs
    end

The LinqDataSourceSelectEventArgs type exposes the following members.

Constructors

  Name Description
Public method LinqDataSourceSelectEventArgs Initializes a new instance of the LinqDataSourceSelectEventArgs class.
Top
Properties

  Name Description
Public property Arguments Gets values that determine how the data is returned.
Public property Cancel Gets or sets a value indicating whether the event should be canceled. (Inherited from CancelEventArgs.)
Public property GroupByParameters Gets the collection of parameters that is used to create the GroupBy clause.
Public property OrderByParameters Gets the collection of parameters that is used to create the OrderBy clause.
Public property OrderGroupsByParameters Gets the collection of parameters that are used to create the clause that specifies how grouped data is sorted.
Public property Result Gets or sets the data object that is used in the data query.
Public property SelectParameters Gets the collection of parameters that is used to create the Select clause.
Public property WhereParameters Gets the collection of parameters that is used to create the Where clause.
Top
Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
Remarks

The LinqDataSourceSelectEventArgs object is passed to event handlers for the Selecting event of the LinqDataSource control. You use the LinqDataSourceSelectEventArgs object to manually specify what data is returned, and how the data is sorted and paged when it is returned. You can programmatically add or remove parameters to the GroupBy, OrderBy, OrderGroupsBy, Select, and Where clauses by using the GroupByParameters, OrderByParameters, OrderGroupsByParameters, SelectParameters, and WhereParameters collections.

The Result property enables you to change the data object that is used for the query. If you assign an object to the Result property, that object will be used for queries instead of the object specified in the TableName property of the LinqDataSource control.

The Arguments property enables you to customize how returned data is sorted and paged. The data-bound control passes sorting and paging properties through the Arguments property. If you have to manually handle sorting or paging, set the AutoSort property or AutoPage property of the LinqDataSource control to false. You can then perform the customized query for sorting or paging in a handler for the Selecting event.

If the RetrieveTotalRowCount property is set to true, you must return a value for the TotalRowCount property.

Examples

The following example shows how to set the Result property to the result of a search made by using language-integrated query (LINQ).

Visual Basic

Protected Sub LinqDataSource_Selecting(sender As Object, e As LinqDataSourceSelectEventArgs)
    Dim exampleContext As New ExampleDataContext()

    e.Result = From p In exampleContext.Products Where p.Category = "Beverages"
               Select New With { _
                    Key .ID = p.ProductID, _
                    Key .Name = p.Name _
    }
End Sub


C#

protected void LinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
    ExampleDataContext exampleContext = new ExampleDataContext();

    e.Result = from p in exampleContext.Products 
         where p.Category == "Beverages"
         select new {
           ID = p.ProductID,
           Name = p.Name
         };
}


The following example shows how to set the Result property to an array of string values that is defined in the Web page.

Visual Basic

Partial Class Default3
    Inherits System.Web.UI.Page

    Dim citiesArray() As String = _
    { _
        "Atlanta", _
        "Charlotte", _
        "Denver", _
        "New York", _
        "San Francisco" _
    }


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub


    Protected Sub LinqDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles LinqDataSource1.Selecting
        Dim cities = From city In citiesArray _
                     Where city > "B" _
                     Select city
        e.Result = cities
        ' Or we could set e.Result = citiesArray to return all rows.
    End Sub

End Class


C#

public partial class Default3 : System.Web.UI.Page
{
    string[] citiesArray = 
    { 
        "Atlanta", 
        "Charlotte", 
        "Denver", 
        "New York", 
        "San Francisco" 
    };

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void LinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        var cities = from city in citiesArray
                     where city.CompareTo("B") > 0
                     select city;
        e.Result = cities;
        // Or we could set e.Result = citiesArray to return all rows.
    }
}


Version Information

.NET Framework

Supported in: 4, 3.5
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference

Other Resources