How do I get data from a LinqDataSource from code behind RRS feed

  • Question

  • User-501461518 posted

    Hi. I'm sure that this is simple. If I have a Linqdatasource that isn't connected to a a bound control on my page how do I use the data source to read data in the code behind. ie


    var query = (from x in linqdatasource select x)

    What I actually want to do is create a data array (myArray) within the code, read all of the data from the linqdatasource (selecting 1 field to form tableDataArray), then compare the two arrays and then write (insert) those into in myArray that are not already in the datasource to the datasource (ie execute an insert back on the datasource).

    Help would be appreciated. Once I've done it once it will be obvious.#


    Thursday, November 18, 2010 11:41 AM


  • User1224194097 posted

    If the LinqDataSource is in the page,

    Set OnSelectedEvent Handler for the LinqDataSource and get the result from Event Arguments.

    protected void LinqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e)
        //Get result here
        var result = e.Result;

    If the LDS is dynamic, you need to add event  handler

    LinqDataSource1.Selected += new EventHandler<LinqDataSourceStatusEventArgs>(LinqDataSource1_Selected);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 18, 2010 9:46 PM