LinqDataSource.Selecting 이벤트

정의

데이터 검색 작업 전에 발생합니다.

public:
 event EventHandler<System::Web::UI::WebControls::LinqDataSourceSelectEventArgs ^> ^ Selecting;
public event EventHandler<System.Web.UI.WebControls.LinqDataSourceSelectEventArgs> Selecting;
member this.Selecting : EventHandler<System.Web.UI.WebControls.LinqDataSourceSelectEventArgs> 
Public Custom Event Selecting As EventHandler(Of LinqDataSourceSelectEventArgs) 

이벤트 유형

예제

다음 예제에서는 이벤트 처리기는 Selecting 이벤트입니다. 처리기는 웹 페이지의 문자열 값 배열에서 값을 검색하는 쿼리를 만듭니다.

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

다음 예제에서는 저장 프로시저를 나타내는 메서드에서 반환되는 개체에 속성을 할당 Result 하는 방법을 보여 줍니다.

Protected Sub LinqDataSource_Selecting(ByVal sender As Object, _  
        ByVal e As LinqDataSourceSelectEventArgs)  
    Dim exampleContext As ExampleDataContext = New ExampleDataContext()  
    e.Result = exampleContext.GetRegisteredCustomers()  
End Sub  
protected void LinqDataSource_Selecting(object sender,   
        LinqDataSourceSelectEventArgs e)  
{  
    ExampleDataContext exampleContext = new ExampleDataContext();  
    e.Result = exampleContext.GetRegisteredCustomers();  
}  

설명

Selecting 다음 작업을 수행하기 위해 이벤트를 처리합니다.

  • 데이터 검색에 대한 매개 변수를 수정합니다.

  • 프로그래밍 방식으로 쿼리를 생성합니다.

  • 정렬 또는 페이징에 대한 값을 수정합니다.

  • 사용자 지정 정렬 또는 페이징을 수행합니다.

  • 데이터 검색 작업을 취소합니다.

LinqDataSourceSelectEventArgs 이벤트의 이벤트 처리기에 전달되는 개체에는 데이터 검색 작업에 대한 매개 변수가 포함됩니다. 쿼리가 실행되기 전에 이벤트 처리기에서 Selecting 매개 변수를 수정하거나 새 결과 집합을 만들어 속성에 Result 할당할 수 있습니다.

이 이벤트에 대한 처리기에서 사용자 지정 정렬 또는 페이징을 구현하는 기능은 에 바인딩 LinqDataSource된 컨트롤에 의해 제한될 수 있습니다. 예를 들어 컨트롤의 열 머리글을 클릭하면 컨트롤은 이벤트 처리기에서 설정한 순서를 재정의 GridView 할 수 있는 자동 정렬을 수행합니다.

이벤트에 대한 이벤트 처리기에서 예외가 Selecting throw되는 경우 해당 이벤트 처리기에서 예외를 처리해야 합니다. 예외는 이벤트에 대한 Selected 이벤트 처리기에 전달되지 않습니다(개체의 LinqDataSourceStatusEventArgs 속성을 통해Exception). 속성에는 Exception 이벤트 후에 Selecting throw되는 예외만 포함됩니다.

적용 대상