Get the ResultSet Returned by LINQDatasource Control in CodeBehind
LinqDataSource control exposes some handful of events that gets raised before and after fetching the data from the database. At times, it is required to get the result returned by the LinqDataSource control from codebehind file for some specific reasons. We can use the OnSelected event to do this. This event will be raised once the data is fetched from the database.
The below code will help us to do that.
ASPX
<asp:GridView ID="GridView2" runat="server" DataSourceID="LinqDataSource2">
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource2" runat="server"
ContextTypeName="DataClassesDataContext" TableName="Employees"
onselected="LinqDataSource2_Selected">
</asp:LinqDataSource>
CodeBehind
protected void LinqDataSource2_Selected(object sender, LinqDataSourceStatusEventArgs e)
{
List<Employee> list = e.Result as List<Employee>;
}
|