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

  • Home
  • SEARCH
  • 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 5933357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:57:44+00:00 2026-05-22T14:57:44+00:00

Ok, I know this cant really be that hard, but im having trouble finding

  • 0

Ok, I know this cant really be that hard, but im having trouble finding any info. I have a gridview on the page that i am filling with data based on a user selected date range(a dropdown list). When the user clicks the button i fill the gridview and display it. This is all done using Linq to Sql. I need to impliment paging and sorting as well. Help PLEASE!!! Below is my button click event… i am open to any suggestions to get this working

protected void btnGenerate_Click(object sender, EventArgs e)
     {
         int dateRange =0;
         if (rbDateList.Checked)
         {
             switch (ddlDateRange.SelectedIndex)
             {
                 case 0:
                     dateRange = 30;
                     break;
                 case 1:
                     dateRange = 60;
                     break;
                 case 2:
                     dateRange = 90;
                     break;
                 default:
                     dateRange = 30;
                     break;
             }
         }
         GYTDataContext gt = new GYTDataContext();
         var productList = from o in gt.PurchaseOrderDetails
                           join p in gt.Products on o.ProductId equals p.ProductId
                           join h in gt.PurchaseOrderHeaders on o.PurchaseOrderId equals h.PurchaseOrderId
                           where h.OrderDate>DateTime.Now.AddDays(-dateRange)
                           group o by o.ProductId into orderedItems
                           select new
                           {
                               orderedItems.Key,
                               QuantityOrdered = orderedItems.Sum(s => s.OrderQuantity)
                           };
         var totalOrderInfo = from p in productList
                              join prod in gt.Products
                              on p.Key equals prod.ProductId
                              select new
                              {
                                  prod.Reference,
                                  UnitPrice = prod.Price,
                                  prod.ManufacturerProductId,
                                  p.QuantityOrdered,
                                  TotalCost = prod.Price * Convert.ToInt32(p.QuantityOrdered)
                              };

        gvOrderReport.DataSource = totalOrderInfo;
         gvOrderReport.DataBind();
         gvOrderReport.Visible = true;
  • 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-22T14:57:45+00:00Added an answer on May 22, 2026 at 2:57 pm

    I had the same problem as you.
    Most examples of linqdatasource, ilustare the WhereParameters > controlparameter functionality which is cool but not that powerful.

    The answer is simple:
    Use a LinqDataSource and just implement the “onselecting” event pass whatever kind of data you wish.

    Here is a short example with full filtering-paging-ordering capabilities
    (also note that the populated sql is optimal and only requests top 10 records every time)

    ASPX:

    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
    <asp:Button ID="btnFilter" runat="server" Text="Filter" 
        onclick="btnFilter_Click"/>
    
    <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
        onselecting="LinqDataSource1_Selecting">
    </asp:LinqDataSource>
    
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1">
        <Columns>
            <asp:BoundField DataField="FirstName" HeaderText="FirstName" ReadOnly="True" 
                SortExpression="FirstName" />
            <asp:BoundField DataField="MiddleName" HeaderText="MiddleName" ReadOnly="True" 
                SortExpression="MiddleName" />
            <asp:BoundField DataField="LastName" HeaderText="LastName" ReadOnly="True" 
                SortExpression="LastName" />
        </Columns>
    </asp:GridView>
    

    CODEBEHIND:

        protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
        {
            var ctx = new LinqDataSource.DBDataContext();
            IQueryable<Customer> customers = ctx.Customers;
    
            if (!String.IsNullOrEmpty(txtLastName.Text))
                customers = customers.Where ( c => c.LastName.Contains(txtLastName.Text));
    
            e.Result = customers;
        }
    
        protected void btnFilter_Click(object sender, EventArgs e)
        {
            GridView1.DataBind();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this is really basic, but I looked everywhere and I cant
I know this might sound silly but I am finding it hard to understand
I know this is probably a really amateur question, but I can't figure this
I know that they are used to store data, but I have a difficult
I have a problem that I have been thinking about, but I can't really
I don't know why this is so hard for me to find, but I
I know this is an easy question but I can't figure it out or
I know this isn't so complicated but I can't remember how to do. I
i know this is kinda retarded but I just can't figure it out. I'm
I know this is probably on the Internet somewhere but I can't find the

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.