LinqDataSourceSelectEventArgs Class

Definition

Provides data for the Selecting event.

C#
public class LinqDataSourceSelectEventArgs : System.ComponentModel.CancelEventArgs
Inheritance
LinqDataSourceSelectEventArgs

Examples

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

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.

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.
    }
}

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.

Constructors

Properties

Arguments

Gets values that determine how the data is returned.

Cancel

Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
GroupByParameters

Gets the collection of parameters that is used to create the GroupBy clause.

OrderByParameters

Gets the collection of parameters that is used to create the OrderBy clause.

OrderGroupsByParameters

Gets the collection of parameters that are used to create the clause that specifies how grouped data is sorted.

Result

Gets or sets the data object that is used in the data query.

SelectParameters

Gets the collection of parameters that is used to create the Select clause.

WhereParameters

Gets the collection of parameters that is used to create the Where clause.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Produkt Verzie
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also