.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

custom linq to sql statement gridview paging

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

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;

View Complete Post

More Related Resource Links

LINQ to SQL Paging using GridView in C# and ASP.NET 3.5

This tutorial will show you how we can extend the LINQ to SQL Class and create methods that will allow us to page data from a SQL database. C# version.

Gridview custom paging using virtualitemcount



I wanted custom paging in gridview as we were using in datagrid with property virtualitemcount property,

but I am not getting the  virtualitemcount property in gridview.

i dont want to maintain it with datasource control in aspx page.


custom linq select statement


Hello all,

I am attempting to use a function that returns would ideally query only a specific column name based on a variable (opt) sent from my aspx page. Here is a sample of my incorrect code:

Public Function availOption(ByVal objName As String) As String
        Dim itmInfo As Array = Split(objName, "|")
        Dim opt As String = itmInfo(0)
        Dim CatItemID As String = itmInfo(1)
        Dim odc = New OrderDataClassesDataContext()
        Dim avail = From a In odc.CustomOptionLists _
                    Where a.catID = 8 _
                    Select '*** use opt variable here ***
        If avail.ToString = "True" Then
            Return "panelVisible"
            Return "panelInvisible"
        End If

    End Function


I have tried to select a.Equals(opt), but it doesn't return the correct value. I have tried to research dynamicLinq, but it isn't something that I've figured out yet either. Is dynamic the way to go?

Otherwise any other ideas would be greatly appreciated.

Thanks and have a good evening.

Gridview custom paging ODS


I'm trying to come up with a simple way to alphabetically retrieve records from my database. I tried adapting this tutorial to my needs but it didn't work (I'm using VS Express 2010). I'm thinking that I'd rather have an objectdatasource alphabetically access the database through the business layer, and I wrote a specific method for that purpose (the table adapter query works at the dataset level).

But I'm not sure how to write the code to programatically display the letter links, then assign the chosen letter to the objectdatasource query, and also respond to postbacks, etc. as in the tutorial mentioned above.

I'd like to know if using objectdatasource to alphabetically bind data makes sense or complicates things and what would be the best way to go.

Thank you,



AJAX GridView Paging and Sorting using C# in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

GridView Paging Using Ajax in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

Advanced Paging GridView with ASP.NET 2.0/3.5

This is an article about advanced paging GridView with ASP.NET 2.0/3.5. All the HTML, CSS, JavaScript it needs have been embedded into the WizardGridView.dll.

GridView Sorting/Paging : 'REAL' AJAX with Asp.Net Series

This is a continuation of my 'REAL' AJAX with Asp.Net (not Asp.Net AJAX) series posts for those of us trying to stop relying on Asp.Net 'AJAX'.

Ok, nothing too dramatic to start things off, we are going to make some tabled data sortable and pagable all without using a bit of postback. Not only that, but it is going to be incredibly easy!

Manually sorting and paging Gridview without using datasource control

Many a times while working with Gridview we want to work with the paging and sorting functionality without using any datasource control. Gridview is flexible enough to perform these tasks without the use of any datasource control and only a few lines of code.

Optimized Paging and Sorting in ASP.NET GridView

In this article I am going to demonstrate what are the performance drawbacks of using conventional way to page and sort your GridView and then I will demonstrate 'An Optimized way to implement Paging and Sorting'.

Passing Linq Statement between master and content page


I usually work with windows forms, and am just starting to work with ASP.Net, so appologies if this is a dumb question!

I have a master page which has a search button on it. The results of this are built up using a Linq statement and if there are any results, I want to display the results in a contents page.

On the masterpage, I have the following code:

Private _res

    Public Overridable ReadOnly Property SearchRes()
            Return _res
        End Get
    End Property

 Private Sub DoSearch()
   'some code to get a linq result

    If res.Any Then
            _res = res
            Server.Transfer("SearchResults.aspx", True)
            'no results
            LabelNoRes.Visible = True
        End If
 End Sub

On the SearchResults.aspx page I have this code.

Dim m As pxSite = CType(Page.Master, MasterPage)
        If m.SearchRes IsNot Nothing Then
            Label1.Text = "Results found = " & m.SearchRes.Count
        End If

m.searchRes is always nothing. 

What am I doing wrong here?


LINQ with GridView and edit fields


My project includes a grid view which displays information of inventory items (Assets), data is quried from AssetTable. The GridView has a command field to allow editing, below is a description of the tables and how data is displayed


BuildingTable: (BuildingID, BuildingName)

AssetTable: (BuildingID,..,....,....)


ItemTemplate: Using a LINQ query I join the two table and displays in a label control a string which includes BuildingID and BuildingName (5 North Building)

 EditItemTemplate: Using a LINQ query I populate a DropDownList with strings of BuildingID and BuildingName same as above.
Here  issue which I need to resolve:
1.  ItemTemplate display the correct information (BuildingID BuildingName) but when I switch to EditItemTemplate the pair that is 
displayed is the first one on the list, how do I make is scroll to the item which was displayed in the label ?
<asp:CommandField ShowEditButton="True" >
                    <ControlStyle Wi

Custom Grid View Header - Grid view Row Created event vs Gridview row databound events ?


Hi Gurus ,

It happened to add an extra Gridveiw Header in row_databound event , It did worked fine on !Postback but disappered on Page.Postback . Quick google search guided me to move the event to Row_Created event and every thing is okay .

Can any expert post some pointers , differnces between grid row_created vs row_databount with some sample table data created dynamically  behaviour of both the events in !Postback and page.Postback .

Thanks a tonne in Advance and  any inputs will be valued and appreciated .

GridView Paging + Unsupported overload used for query operator 'Distinct'


The issue is two fold in my ASP.NET Web Application. I need to use a custom Distinct() via LINQ to SQL, and then assign thevar as a DataSource to a GridView. If I use the custom Distinct that implements IEqualityComparer, I get "Unsupported overload used for query operator 'Distinct'" exception. but if i somehow get past this, i get "The data source does not support server-side data paging" exception on GridView.DataBind(). here is the code:

distinct_employees =
    (from emp in wsq.LIT_Active_Employees
    where (String.IsNullOrEmpty(ssFirstName.Text) ? (emp.FIRST_NAME == null || emp.FIRST_NAME.StartsWith(String.Empty)) : emp.FIRST_NAME.Contains(ssFirstName.Text)) &&
            (String.IsNullOrEmpty(ssLastName.Text) ? (emp.LAST_NAME == null || emp.LAST_NAME.StartsWith(String.Empty)) : emp.LAST_NAME.Contains(ssLastName.Text)) &&a

LINQ to SQL and Case statement

Working with LINQ I realized that I had to use the simple case statement in my SQL query. There is no special keyword for this. To create a case statement like structure you will have to do it in the select section of the query. Below is an example of the usage of the case statement in LINQ. var t = from n in idc.categories            select new             {                        catName =                         (n.id==1 ? "Cat1" :                        n.id==2 ? "Cat2" :                        n.id==3 ? "Cat3" : "Unknown Category"                        )             }; Here in the above code we are using multiple cases for value 1, 2 and 3

How can I get xmlns:xsi to appear after (instead of before) a custom xmlns="blah" statement?

I need the | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | statement to appear as the second statement after | xmlns="blah" | in an XML file I an trying to generate.  If it appears first the system that consumes the fail is unable to interpret the file. My query: WITH XMLNAMESPACES (DEFAULT 'example', 'http://www.w3.org/2001/XMLSchema-instance' AS xsi) SELECT 'myschema schemav5.xsd' "@xsi:schemaLocation", '27' AS CompanyCode , ISNULL(NULL,'') AS ExampleOfBlankNullField , NULL AS ExampleOfNullField, 2010 AS [Year] , 3 AS [Quarter] FOR XML PATH('CompanyData'), ELEMENTS XSINIL ; The result:   <CompanyData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="example" xsi:schemaLocation="myschema schemav5.xsd"> <CompanyCode>27</CompanyCode> <ExampleOfBlankNullField></ExampleOfBlankNullField> <ExampleOfNullField xsi:nil="true" /> <Year>2010</Year> <Quarter>3</Quarter> </CompanyData> If I could just get that xmlns="example" to be placed before the xmlns:xsi section, then I would be good to go.   Any suggestions on how I can do that? Thank you for your help!

Master-Detail GridView in Single Page example with paging throws error

___http://www.java2s.com/Code/ASP/Data-Binding/MasterDetailGridViewinSinglePage.htmI followed example at the link above.When I enablind paging=true (by pagesize=3).and clicking to pages 2|3|4 etc and so;error occuringIndex was out of range. Must be non-negative and less than the size of the collection.at cs line :sourceProducts.SelectParameters[0].DefaultValue = gridMaster.DataKeys[e.Row.DataItemIndex].Value.ToString();got any idea?what should I make to fix this ? is this error  fixable ?thanks much.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend