Take value based upon textbox value RRS feed

  • Question

  • Hello all, I am creating a gridview that will be populated based upon a linq statement, the sql is as follows:

    SELECT     TOP 10 IDDesc, UnitUserfield1, UnitUserfield2, ProductPercentage
    FROM         tblOnlineReportingCOMPLETEWeights
    WHERE     (MaterialLevel = 'Primary') AND (MaterialText = 'Paper')
    ORDER BY ProductPercentage DESC
    Now, what I would like to do is let the user specify the Top 10, so essentially it is a "Top x" this being defined in a textbox i.e. they type in 50 into the textbox, the linq query is executed and the gridview displays the top 50.

    I understand that using Take is the area I want to look at, is this correct? Is this even possible?!

    Any thoughts, muchly appreciated.

    PS: apologies for asking thick questions, I am very new to all of this!
    Tuesday, November 24, 2009 10:35 AM


  • Yea .Take should be fine.
    using (DataContext db = new DataContext)
       var q = (from t in db.tblOnlineReportingCOMPLETEWeights
                    where t.MaterialLevel == "Primary" AND t.MaterialText == 'Paper')
                    orderby t.ProductPercentage descending
                    select new
       gridview1.Datasource = q;
    • Marked as answer by Yichun_Feng Monday, November 30, 2009 2:31 AM
    Tuesday, November 24, 2009 3:29 PM