Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1014235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:13:24+00:00 2026-05-16T10:13:24+00:00

I have a GridView using LinqDataSource to populate data from table Tickets . The

  • 0

I have a GridView using LinqDataSource to populate data from table Tickets. The LinqDataSource has AutoGenerateWhereClause="True" so that the where clause can be constructed dynamically like this:

<asp:LinqDataSource ID="dsGridView" runat="server" AutoGenerateWhereClause="True"  
     ontextTypeName="TicketsDataContext" TableName="Tickets" OrderBy="ID Descending"  
     EnableDelete="True" OnSelecting="dsGridView_Selecting">  
    <WhereParameters>  
        <asp:SessionParameter Name="AssignedTo" SessionField="user"/>  
        <asp:Parameter Name="Department" DefaultValue="" />  
        <asp:Parameter Name="Category" DefaultValue="" />  
    </WhereParameters>  
</asp:LinqDataSource>

The Where parameters are used with the dropdownlist filters on the header of the gridview. They can be null so that dsGridView will return all records.

My gridview has paging enabled.

Table Ticket has a field called TimeSpent. I would like to calculate the total TimeSpent for all the tickets filtered and display it on Footer.

I could use Linq2SQL on gridView_DataBound to query ALL tickets’ TimeSpent. However, I am confused how to get the total TimeSpent when the gridview is filtered.

I tried to get tickets from LinqDataSourceSelectEventArgs.Result, but it only returned the total TimeSpent for the current page of gridview, not for the whole table.

The problem is, I do not know how many Where parameters will present in the Selecting event. Department can be null and not shown up in WhereParameters, and so can Category.

Something like this:

TicketsDataContext db = new TicketsDataContext();  
var query = from ticket in db.Tickets select ticket;  
foreach (var param in dsGridView.WhereParameters  
{  
    if (!string.IsNullOrEmpty(param.Value))  
        query.query.Where(...)  
}

Does not work of course. Is there any idea how I could tackle this issue? Thanks in advance!

Updated: I ended up reusing the data returned from dsGridView in OnSelected event as below:

protected void dsGridView_Selected(Object sender, LinqDataSourceStatusEventArgs e)  
{  
    var totalTime = (e.Result as List<Ticket>).Sum(t => t.TimeSpent);  
    grvTickets.Columns[7].FooterText = "Sum: " + totalTime.ToString();  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:13:24+00:00Added an answer on May 16, 2026 at 10:13 am

    Start with http://www.albahari.com/nutshell/predicatebuilder.aspx. They go into PredicateBuilder which is good for most of the scenarios you’ll run into. Ultimately you may need to delve into expression trees, but that’s a good deal more advanced.

    From your comment below, it sounds like Dynamic Linq will be a better fit for you:
    http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

    If that doesn’t suffice, you’ll have to build the expression trees yourself. Don’t worry, what you want to do is definitely possible. Might get a bit tricky if you have to do it yourself though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a GridView with LinqDataSource. im using the following technique to populate a
I have a gridview that is using a LinqDataSource for it's datasource. I've added
hello I have a code that pulls the data to the gridview using a
Im using a LINQDataSource to populate a GridView of Universities. Each University has an
I have a GridView that uses LinqDataSource. The GridView has default paging enable. I
I have a gridview that is supposed to refresh using gridView.DataSource = null; gridView.DataBind();
I was using Gridview for a while now and I have noticed that its
How can I populate a GridView using a connection to an Access Database? So
I have a Gridview bound to a linqdatasource. The gridview has a FK. i
Good afternoon all. I have a page that displays data in a gridview based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.