My page has several GridView controls placed on it from the designer.
My datasource is dynamic (DataTable) assigned in the code behide.
On this same page I am creating a GridView control from the code behide and placing it in an asp:table, assigning the properties and styles to duplicate the designer GridViews. Everything works, displays good and column sorting works.
However. If the datasource contains more records then the GridView PageSize I receive the Object reference error. I have tried everything I can think of to no avail. If my datasource contains 30 records and my page size is default 10 or anything less than 30 I will receive the error. If I change the page size to 30 or greater it works fine (No pageing of course) The boolean AllowPaging is set to true. The paging on the GridViews placed on the page from the designer works fine. Just the dynamic GridView causes the error. The datasource for all of the GirdViews are obtained and assigned in the same fashion.
Any suggestions would be greatly appreciated.
2 7407
My page has several GridView controls placed on it from the designer.
My datasource is dynamic (DataTable) assigned in the code behide.
On this same page I am creating a GridView control from the code behide and placing it in an asp:table, assigning the properties and styles to duplicate the designer GridViews. Everything works, displays good and column sorting works.
However. If the datasource contains more records then the GridView PageSize I receive the Object reference error. I have tried everything I can think of to no avail. If my datasource contains 30 records and my page size is default 10 or anything less than 30 I will receive the error. If I change the page size to 30 or greater it works fine (No pageing of course) The boolean AllowPaging is set to true. The paging on the GridViews placed on the page from the designer works fine. Just the dynamic GridView causes the error. The datasource for all of the GirdViews are obtained and assigned in the same fashion.
Any suggestions would be greatly appreciated.
You've likely tried this already but have you set the GridView's paging property to allow paging?
Edit: Errr...sorry should have read the whole message...This sounds a bit crazy.
Double check the allow paging again though just to be sure.
Could you post the code that creates your GridView and data source please?
Data Source for the GridView is a System.Data.DataTable with proper field names and types.
As soon as the gv.DataBind() is executed I receive the Error.
The gvInvoices_DataBound event does not fire.
GridView Source: -
gv = new System.Web.UI.WebControls.GridView();
-
gv.ID = "gvInvoice" + aPoints[i];
-
gv.AllowPaging = true;
-
gv.AllowSorting = true;
-
gv.AutoGenerateColumns = false;
-
gv.BackColor = System.Drawing.Color.White;
-
gv.BorderColor = System.Drawing.Color.FromArgb(231,231,255);
-
gv.BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
-
gv.BorderWidth = new System.Web.UI.WebControls.Unit("1px");
-
gv.CellPadding = 3;
-
gv.ShowFooter = true;
-
gv.PageSize = 50;
-
// GridView Columns
-
gvc = new System.Web.UI.WebControls.BoundField();
-
gvc.DataField = "invoice_number";
-
gvc.HeaderText = "Number";
-
gvc.ReadOnly = true;
-
gvc.SortExpression = "number";
-
gvc.ItemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
-
gv.Columns.Add(gvc);
-
gvc = new System.Web.UI.WebControls.BoundField();
-
gvc.DataField = "amount";
-
gvc.HeaderText = "Amount";
-
gvc.ReadOnly = true;
-
gvc.SortExpression = "amount";
-
gvc.ItemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
-
gv.Columns.Add(gvc);
-
// Grid View Styles
-
gv.RowStyle.BackColor = System.Drawing.Color.FromArgb(231,231,255);
-
gv.RowStyle.ForeColor = System.Drawing.Color.FromArgb(74,60,140);
-
gv.RowStyle.Font.Names = new string[] { "Tahoma","Arial","Verdana","Trebuchet","Sans-Serif" };
-
gv.RowStyle.Font.Size = new System.Web.UI.WebControls.FontUnit("8pt");
-
gv.SelectedRowStyle.BackColor = System.Drawing.Color.FromArgb(115,138,156);
-
gv.SelectedRowStyle.Font.Bold = true;
-
gv.SelectedRowStyle.ForeColor = System.Drawing.Color.FromArgb(247,247,247);
-
gv.PagerStyle.BackColor = System.Drawing.Color.FromArgb(231,231,255);
-
gv.PagerStyle.ForeColor = System.Drawing.Color.FromArgb(74,60,140);
-
gv.PagerStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
-
gv.PagerStyle.Font.Names = new string[] { "Tahoma","Arial","Verdana","Trebuchet","Sans-Serif" };
-
gv.PagerStyle.Font.Size = new System.Web.UI.WebControls.FontUnit("9pt");
-
gv.HeaderStyle.ForeColor = System.Drawing.Color.FromArgb(247,247,247);
-
gv.HeaderStyle.BackColor = System.Drawing.Color.FromArgb(74,60,140);
-
gv.HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
-
gv.HeaderStyle.Font.Names = new string[] { "Tahoma","Arial","Verdana","Trebuchet","Sans-Serif" };
-
gv.HeaderStyle.Font.Size = new System.Web.UI.WebControls.FontUnit("9pt");
-
gv.HeaderStyle.Font.Bold = true;
-
gv.HeaderStyle.Wrap = true;
-
gv.AlternatingRowStyle.BackColor = System.Drawing.Color.FromArgb(247,247,247);
-
gv.FooterStyle.BackColor = System.Drawing.Color.FromArgb(181,199,222);
-
gv.FooterStyle.ForeColor = System.Drawing.Color.FromArgb(74,60,140);
-
gv.FooterStyle.Font.Names = new string[] { "Tahoma","Arial","Verdana","Trebuchet","Sans-Serif" };
-
gv.FooterStyle.Font.Size = new System.Web.UI.WebControls.FontUnit("8pt");
-
gv.DataBound += new System.EventHandler(gvInvoices_DataBound);
-
gv.PageIndexChanging += new System.Web.UI.WebControls.GridViewPageEventHandler(gvInvoices_PageIndexChanging);
-
gv.Sorting += new System.Web.UI.WebControls.GridViewSortEventHandler(gvInvoices_Sorting);
-
gv.DataSource = tblTmp1;
-
gv.DataBind();
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chris Magoun |
last post by:
I suddenly received an unexpected error in my project. I have been working
on this project for some time without this issue. Nothing has changed in the
form that caused the exception. A little...
|
by: blash |
last post by:
Can someone help me? I really don't have a clue.
My company staff told me they often got such error: "Object reference
not set to an instance of an object." when they are in search result
page...
|
by: Microsoft |
last post by:
When I try this in my code I alwas get an errormessage: "Object reference
not set to an instance of an object"
Dim g As System.Drawing.Graphics
g.DrawString("Test", New Font("Arial", 12,...
|
by: Brett |
last post by:
I'm not sure why I keep getting this error, "Object reference not set to an
instance of an object".
Private Function somefunction() as string
Dim MyCurrentClass As New Class1
Try
For i As...
|
by: David Lozzi |
last post by:
Howdy,
I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders!
Now I am making a public function that will take the...
|
by: rushikesh.joshi |
last post by:
Hi All,
I have created my own WebControl and want to add it in my aspx page at
runtime.
it's compiling perfectly, but when i m going to execute, it gives me
error of "Object reference not set...
|
by: SAL |
last post by:
I am getting the following ERROR in my WebApp on line 30:
Server Error in '/TestWebApp' Application.
--------------------------------------------------------------------------------
Object...
|
by: Nathan Sokalski |
last post by:
I have a UserControl that I declare programmatically as follows:
Dim userctrl as New rightside_portal()
The codebehind file for this UserControl looks like the following:
Partial Public...
|
by: arun1985 |
last post by:
In the project i am using i am having the following code and when i upload it to the server.Its givig me the following error in the global.cs file.
Server Error in '/' Application. ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |