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 7223
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();
-
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
1 post
views
Thread by Chris Magoun |
last post: by
|
6 posts
views
Thread by blash |
last post: by
|
18 posts
views
Thread by Microsoft |
last post: by
|
7 posts
views
Thread by Brett |
last post: by
|
15 posts
views
Thread by David Lozzi |
last post: by
|
4 posts
views
Thread by rushikesh.joshi |
last post: by
|
3 posts
views
Thread by SAL |
last post: by
|
1 post
views
Thread by Nathan Sokalski |
last post: by
| | | | | | | | | | | | |