1

I'm assigning list to e.Result in LinqDataSource OnSelecting Event result contains 5 rows in it. On Execution of OnSelected Event the result doesn't contains any rows . Why is this happening ?... I'm I missing any thing? Here is my code of Selecting event

protected new void OnDataSourceSelecting(object sender, LinqDataSourceSelectEventArgs e)
     {
        int AdminAccessID = 1;
List<VIEW_ManagerOwned> result = _dataContext.VIEW__ManagerOwneds.Where(ma => (ma.LastName == "West") & (ma.FirstName == "Stacie") & ma.AdminUserAccessID == Convert.ToInt32(AdminAccessID) & ma.SecurityUserID == Convert.ToInt32(1766)).ToList();
        e.Result = result;
     }

protected void ListLinqDataSource_Selected(object sender, LinqDataSourceStatusEventArgs e)
    {

    }
user3270152
  • 75
  • 2
  • 11

1 Answers1

2

I'm no expert on LinqDataSourceSelectEventArgs but my suspicion is that you are expecting the value of e.Result to be passed to the next event hander, in this case ListLinqDataSource_Selected but it is likely that this handler is getting a different set of event args which would explain why you are not getting your list in e.Result from the Selecting handler.

One potential solution is to cache the value of result in a class level variable so that you can access it after you have it populated.

Again I could be wrong about the event handler not sending the previous event args to the next handler, but I believe this is the most likely cause of the issue.

ADDITIONS: Simply regarding your code, are you sure you want to use bitwise & in your LINQ statement and not a conditional &&? There are times to use each but you may get undesired results using the & operator here. Also, consider formatting your code with less horizontal space and more vertical space, it is difficult to read when you have such a long line of code. Also generally you do not want to assign to event args the way you are doing it, as you can see it is not producing the results you are expecting. (no pun intended on results).

Evan L
  • 3,805
  • 1
  • 22
  • 31