.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

SPGridView grouping not working with sorting or paging

Posted By:      Posted Date: October 09, 2010    Points: 0   Category :SharePoint

Anybody can help with the issue here? I have a SPGridView using ObjectDataSource with grouping, sorting and paging enabled. Once i clicked on the next button or the sort header, it's give the "An unexpected error has occurred." on screen. 

Error in the 12 hive logs
Application error when access /Web Pages/TestGridView.aspx, Error=Value cannot be null.  Parameter name: container
at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName)
at Microsoft.SharePoint.WebControls.SPGridView.OnRowCreated(GridViewRowEventArgs args)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
at Microsoft.SharePoint.WebControls.SPGridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()

View Complete Post

More Related Resource Links

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 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'.

SPGridView Paging In Webpart

I'm working on making results display web part and I'm displaying things using an SPGridView.  Things are working fine, except that I can't get the paging to work correctly.

The paging controls are displaying, but when I click to the next page, it reloads the page I'm on and I loose my results (basically the data isn't getting sent to the next page).  Below is the code I have:

Button cmdSearch;
        TextBox txtQueryText;
        DropDownList scopesDropDown;
        Label lblQueryResult;
        SPGridView grdResults;

        protected override void CreateChildControls()
            // Create and add the controls that make up the
            // user interface of the web part. 

            scopesDropDown = new DropDownList();


            txtQueryText = new TextBox();

            cmdSearch = new Button();
            cmdSearch.Text = "Start Search";
            cmdSearch.Click += new EventHandler(cmdSearch_Click);

            lblQueryResult = new Label();

        void cmdSearch_Click(object sender, EventArgs e)

DataGrid Paging not working

I got DataGrid Paging functionality on, I can see the paging 1,2,3,4,5.... but when i try to click on it to go to that page the datagrid just goes blank (does not render any record anything). My code is below: <asp:DataGrid ID="dgArticles" AllowPaging="true" Width="100%" AllowSorting="True" AutoGenerateColumns="False" runat="server" OnPageIndexChanged="dgArticles_PageIndexChanged" PageSize="15" EnableViewState= "true"> <ItemStyle Font-Names="Arial" Font-Size="12px" /> <HeaderStyle Font-Bold="true" ForeColor="#FFFFFF" Font-Names="Arial" Font-Size="14px" BackColor="#B2C1D1" /> <PagerStyle Mode="NumericPages" CssClass="FooterButton" Font-Size="Large" /> <AlternatingItemStyle BackColor="#EAEAEA" /> <Columns> <asp:BoundColumn DataField="ContentID" HeaderText="Content ID" /> <asp:HyperLinkColumn DataTextField="Headline" DataNavigateUrlField="ContentID" DataNavigateUrlFormatString=

How to handle sorting and paging when objectdatasource is being built dynamically?

i am building my objectdatasource dynmically when certain buttons are clicked on the page.. and with that the gridview is being displayed with the results of the objectdatasource that was built. So my gridview code looks like this: <asp:GridView ID="GridView1" runat="server" Visible="False" Width="85%"> <EmptyDataTemplate> There are no results for your search. Please try again. </EmptyDataTemplate> </asp:GridView> How can i enable sorting and paging if the datasource is being built on button click event?

gridview checkbox sorting not working

Hi All,I have a grid view which populates data just for viewing purpose(report) . One field shows the Active/inactive status for which I am showing a checkbox..if data in database is 1 then the checkbox will be checked otherwise it'll not be checked. This field is inactive so that the User does not check/uncheck it. The issue is that this field cannot be sorted. All the fields in the gridview are being sorted. Below is the code for the checkbox column. <asp:TemplateField HeaderText="InActive" SortExpression="Inactive"><HeaderTemplate ><asp:Label ID="lblStat" CssClass="copyLabel" Text="Inactive" CommandArgument="Inactive"                    runat="server"></asp:Label></HeaderTemplate> <ItemTemplate><asp:CheckBox runat="server" ID="chkStatus" Enabled="false"/></ItemTemplate></asp:TemplateField>I have given AllowSorting="True" in the gridview properties. The code in the gridview sorting event works fine for all other columns except the checkbox column. Please help and suggest some scenarios/links so that I can achieve sorting for the checkbox column also.Thanks in advance.

maintain sorting data during paging

when i sort the grid and it is display in sorted order and when i go to next page it will show data in default order. how to maintain sorting order duing paging

Paging on a different column than the sorting column



Situation: SQL database, Linq to SQL class a ASP.NET page with a LinqDataSource and a gridview.

The table has a ID field, a date field and a Serialnr field.

In my Grid I like to Page on the datefield but to sort on the serialnr field ( or a selectable other field).

Is that possible? Standard the paging is always done on the sort field and when you select a different sort field the page jumps back to the first page., and paging is then done over that sorted column.



Paging and sorting using different columns



Situation: SQL database, Linq to SQL class a ASP.NET page with a LinqDataSource and a gridview.

The table has a ID field, a date field and a Serialnr field.

In my Grid I like to Page on the datefield but to sort on the serialnr field (or a selectable other field.)

Is that possible? Standard the paging is always done on the sort field and when you select a different sort field the page jumps back to the first page, and paging is then done over the sorted column.


Calculated field Sorting Now Working , but have performance question


 Thanks to mitja.GTI.

My sorting is working ...

although i had to take the table that has my calculated column and make a view (so i could filter) and then bind the gridview to the view.

My question is as this.

1.) in order to get my calculated field i had to load my data into a table (as suggested)

2.)Add a column to the table and perform calculations

3.)make a dataview from the tables because i could not get the Gridview.datasource= ds.tables("loads").select("Deadhead <= " & sngRadius

4.)the largest of the 3 tables my query is based on contains about 7000 records. The way i have the logic & programming now everytime a new "truck location" is put in the textbox1 and "find loads/button1" is clicked. It calculates the deadhead miles of all 7000 records before filtering. I am filtering based on the deadhead miles.

Does anyone have any recomendation about how to speed this up a bit.

Also in order to get paging to work i had to rebind/filter the data again ... means looping through all 7000 records each time paging is called. This seems terribly ineffecient as i am already forced to use access instead of SQL.


Formview paging not working with objectdatasource and viewstate setup


I was able to get the formview bound to the objectdatasource, it works great for the first record, but when i select the next record it gives me error  below is all my code, if there is something else that i need to post please let me know.


I opt'd for using formview since it has paging ability.. But now that i got that working, selecting the next record gives me an error.

This is what i have as my button event:


        protected void btnSearchHealthRecords_Click(object sender, EventArgs e)
            if (ddlVehNum.SelectedValue == "0")
                rfvVehNum.IsValid = false;
                ObjectDataSource1.SelectMethod = "HealthRecords";
                ObjectDataSource1.SelectParameters.Add("vehiclenum", TypeCode.String, ddlVehNum.SelectedValue.ToString());

                ViewState["MethodName"] = "HealthRecords";

                FormView1.Visible = true;

                Session["btClick"] = "5";
                sn.Visible = true;


        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

Sorting and Paging in DataGrid which is inside asp:wizard



Would it be possible to do Sorting and Paging in a DataGrid, My dataGrid is place inside an asp:wizard which is inside an Update Panel.

<asp:UpdatePanel ID="upEditusr" runat="server">
<asp:Wizard ID="Wizard1" runat="server" CssClass="wizUsrAccess" displaycancelbutton="True" 
              oncancelbuttonclick="OnCancelButtonClick" onfinishbuttonclick="OnFinishButtonClick" OnNextButtonClick="OnNextButtonClick" ActiveStepIndex="0" BorderWidth="1px" DisplaySideBar="false">
               <asp:Label ID="SideBarInfo" OnPreRender="InitSideBarLbl" runat="server" /> 
               <asp:DataList ID="SideBarList" OnPreRender="LoadSideBar" RepeatLayout="Flow" Style="display:none;" runat="server"> 
                       <asp:LinkButton ID="SideBarButton" Visible="false" runat="server"></asp:LinkButton> 
                   <SelectedItemStyle Font-Bold="True"  />            

Gridview cancel,sorting,paging


Please can you give me the code for gridview sorting,paging and cancel and please also explain methe code for each line.....otherwise i wont understand the code

Paging not working with two controls- Dropdownlist & Listview


So I am using EW + Access database to create a page.

This page contains two controls. First control is Dropdownlist which databinds with second control Listview.

This listview has paging on becuse of multiple pages. If I don't use QueryStringField paging works but if I use QueryStringField paging doesn't work and it goes back to first option of Dropdownlist.

I need paging to access specific records.

Can anybody help me with this issue.

Thx in advance!!

Paging in SPGridView in Webpart



I am writing a share-point web part to perform search. So user inputs the keyword and i search from different servers and present him the results in Grid View along with paging. To accomplish this i started with different articles and finally wrote following piece of code, which so far is unable to handle paging. It shows the first result but for all other pages , naha, nada, empty ,


So here is the elegant piece of code , i got from googling ..




 #region variables
    DataTable MainDT = null;  
    private SPGridView grid;
    private ObjectDataSource gridDS;
    private LinkButton btnSearch;

 protected sealed override void CreateChildControls()
btnSearch= new LinkButton();
        btnSearch.Text = "Search";
        btnSearch.Click += new EventHandler(btnSearch_Click);
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