Solved

webpart error

Posted on 2011-03-16
5
1,249 Views
Last Modified: 2012-05-11
When I deploy my webpart, I get this message on the page.:

Object reference not set to an instance of an object error

Any ideas?

Thanks!
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace WSPBuilderProject1
{
    [Guid("cc7b48e0-cb96-4b56-b1e8-8c758e065634")]
    public class WebPartFeature1 : Microsoft.SharePoint.WebPartPages.WebPart
    {
        private bool _error = false;
        private string _myProperty = null;

        SPSite mySite = SPContext.Current.Site;
        SPWeb myWeb;
        SPList myList;

        GridView myGridView = new GridView();
        
        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [System.ComponentModel.Category("My Property Group")]
        [WebDisplayName("MyProperty")]
        [WebDescription("Meaningless Property")]
        public string MyProperty
        {
            get
            {
                if (_myProperty == null)
                {
                    _myProperty = "Hello SharePoint";
                }
                return _myProperty;
            }
            set { _myProperty = value; }
        }


        public WebPartFeature1()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        /// <summary>
        /// Create all your controls here for rendering.
        /// Try to avoid using the RenderWebPart() method.
        /// </summary>
        protected override void CreateChildControls()
        {
            if (!_error)
            {
                try
                {

                    base.CreateChildControls();

                    myWeb = SPContext.Current.Web;
                    myList = myWeb.Lists["HOTLINE"];
                    SPListItemCollection results = myList.Items;

                    //Create the datatable object
                    DataTable table;
                    table = new DataTable();
                    table.Columns.Add("Type", typeof(string));
                    table.Columns.Add("Name", typeof(string));
                    table.Columns.Add("Modified", typeof(string));
                    table.Columns.Add("Modified By", typeof(string));
                    table.Columns.Add("STATUS", typeof(string));
                    table.Columns.Add("PRIORITY CODE", typeof(string));
                    table.Columns.Add("PRIORITY", typeof(string));
                    table.Columns.Add("CASE NUMBER", typeof(string));
                    table.Columns.Add("COMPLETE", typeof(string));

                    //Create the rows for each splistitem
                    DataRow row;
                    foreach (SPListItem result in results)
                    {
                        row = table.Rows.Add();
                        row["Type"] = result["Type"].ToString();
                        row["Name"] = result["Name"].ToString();
                        row["Modified"] = result["Modified"].ToString();
                        row["Modified By"] = result["Modified By"].ToString();
                        row["STATUS"] = result["STATUS"].ToString();
                        row["PRIORITY CODE"] = result["PRIORITY CODE"].ToString();
                        row["PRIORITY"] = result["PRIORITY"].ToString();
                        row["CASE NUMBER"] = result["CASE NUMBER"].ToString();
                        row["COMPLETE"] = result["COMPLETE"].ToString();
                    }

                    myGridView.AutoGenerateColumns = false;
                    myGridView.AllowPaging = true;
                    myGridView.PageSize = 100;

                    BoundField HL_TYPE = new BoundField();
                    HL_TYPE.HeaderText = "TYPE";
                    HL_TYPE.DataField = "TYPE";
                    HL_TYPE.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_TYPE.ItemStyle.Wrap = false;
                    myGridView.Columns.Add(HL_TYPE);

                    BoundField HL_NAME = new BoundField();
                    HL_NAME.HeaderText = "NAME";
                    HL_NAME.DataField = "NAME";
                    HL_NAME.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_NAME.ItemStyle.Wrap = false;
                    myGridView.Columns.Add(HL_NAME);

                    BoundField HL_MODIFIED = new BoundField();
                    HL_MODIFIED.HeaderText = "MODIFIED";
                    HL_MODIFIED.DataField = "MODIFIED";
                    HL_MODIFIED.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_MODIFIED.ItemStyle.Wrap = false;
                    myGridView.Columns.Add(HL_MODIFIED);

                    BoundField HL_MODIFIED_BY = new BoundField();
                    HL_MODIFIED_BY.HeaderText = "MODIFIED BY";
                    HL_MODIFIED_BY.DataField = "MODIFIED BY";
                    HL_MODIFIED_BY.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_MODIFIED_BY.ItemStyle.Wrap = false;
                    myGridView.Columns.Add(HL_MODIFIED_BY);

                    BoundField HL_STATUS = new BoundField();
                    HL_STATUS.HeaderText = "STATUS";
                    HL_STATUS.DataField = "STATUS";
                    HL_STATUS.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_STATUS.ItemStyle.Wrap = false;
                    myGridView.Columns.Add(HL_STATUS);

                    BoundField HL_PRIORITY_CODE = new BoundField();
                    HL_PRIORITY_CODE.HeaderText = "PRIORITY CODE";
                    HL_PRIORITY_CODE.DataField = "PRIORITY CODE";
                    HL_PRIORITY_CODE.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_PRIORITY_CODE.ItemStyle.Wrap = false;
                    myGridView.Columns.Add(HL_PRIORITY_CODE);

                    BoundField HL_PRIORITY = new BoundField();
                    HL_PRIORITY.HeaderText = "PRIORITY";
                    HL_PRIORITY.DataField = "PRIORITY";
                    HL_PRIORITY.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_PRIORITY.ItemStyle.Wrap = false;
                    myGridView.Columns.Add(HL_PRIORITY);

                    BoundField HL_CASE_NUMBER = new BoundField();
                    HL_CASE_NUMBER.HeaderText = "CASE NUMBER";
                    HL_CASE_NUMBER.DataField = "CASE NUMBER";
                    HL_CASE_NUMBER.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_CASE_NUMBER.ItemStyle.Wrap = false;
                    myGridView.Columns.Add(HL_CASE_NUMBER);

                    BoundField HL_COMPLETE = new BoundField();
                    HL_COMPLETE.HeaderText = "COMPLETE";
                    HL_COMPLETE.DataField = "COMPLETE";
                    HL_COMPLETE.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_COMPLETE.ItemStyle.Wrap = false;
                    myGridView.Columns.Add(HL_COMPLETE);


                    // Your code here...
                    this.Controls.Add(new LiteralControl(this.MyProperty));
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

        /// <summary>
        /// Ensures that the CreateChildControls() is called before events.
        /// Use CreateChildControls() to create your controls.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            if (!_error)
            {
                try
                {
                    base.OnLoad(e);
                    this.EnsureChildControls();

                    // Your code here...
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
        protected override void Render(HtmlTextWriter writer)
        {
            SPSite mySite = SPContext.Current.Site;
            SPWeb myWeb = SPContext.Current.Web;
            SPList myList = myWeb.Lists["HOTLINE"];

            myGridView.DataSource = myList;
            //spDataSource.List = myList;
            //SPGridView1.DataSource = spDataSource;
            myGridView.DataBind();
            //SPGridView1.DataBind();
            myGridView.RenderControl(writer);
            //SPGridView1.RenderControl(writer);
        }
        /// <summary>
        /// Clear all child controls and add an error message for display.
        /// </summary>
        /// <param name="ex"></param>
        private void HandleException(Exception ex)
        {
            this._error = true;
            this.Controls.Clear();
            this.Controls.Add(new LiteralControl(ex.Message));
        }
    }
}

Open in new window

0
Comment
Question by:Isaac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ChouhanR
ID: 35154597
Set callstack="true" and Customerrors="Off" and then post here the error that is displayed so that we could montior and tell you the line which is creating problem...

As off now..i think something is failing to get initialize either row or column or table.. need to check the error then we can tell...

Also.. instead of dynamic datatable, while accessing the list you can make a DataTable collection and then bind it to Gridview.. you can then set all you CSS properties to Gridview...
0
 
LVL 5

Author Comment

by:Isaac
ID: 35156307
I made the changes you suggested and when I refresh the page, I still see the same error.

>>instead of dynamic datatable, while accessing the list you can make a DataTable collection and then bind it to Gridview.. you can then set all you CSS properties to Gridview... <<
Could you please show how I would do that? sample?

Thanks
0
 
LVL 5

Author Comment

by:Isaac
ID: 35157268
Ok.

I changed the above code and used an SPGridView in place of the GridView.  See code below and Stack Trace:

I'v never read a stack trace before.  Please help!

Thanks.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace HotlineWebPart_WP
{
    [Guid("9c641d46-007f-4c25-9d0d-f64e34d7960d")]
    public class HotLine_WebPart : Microsoft.SharePoint.WebPartPages.WebPart
    {
        private bool _error = false;
        private string _myProperty = null;
        //SPSite mySite = new SPSite(@"http://landis");
        SPSite mySite = SPContext.Current.Site;
        SPWeb myWeb;
        SPList myList;

        SPGridView SPGridView1 = new SPGridView();
        SPDataSource spDataSource = new SPDataSource();

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [System.ComponentModel.Category("My Property Group")]
        [WebDisplayName("MyProperty")]
        [WebDescription("Meaningless Property")]
        public string MyProperty
        {
            get
            {
                if (_myProperty == null)
                {
                    _myProperty = "Hello SharePoint";
                }
                return _myProperty;
            }
            set { _myProperty = value; }
        }


        public HotLine_WebPart()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        /// <summary>
        /// Create all your controls here for rendering.
        /// Try to avoid using the RenderWebPart() method.
        /// </summary>
        protected override void CreateChildControls()
        {
            if (!_error)
            {
                try
                {

                    base.CreateChildControls();

                    myWeb = SPContext.Current.Web;
                    //myWeb = mySite.OpenWeb();
                    myList = myWeb.Lists["HOTLINE"];
                    SPListItemCollection results = myList.Items;

                    //Create the datatable object
                    DataTable table;
                    table = new DataTable();
                    table.Columns.Add("Type", typeof(string));
                    table.Columns.Add("Name", typeof(string));
                    table.Columns.Add("Modified", typeof(string));
                    table.Columns.Add("Modified By", typeof(string));
                    //table.Columns.Add("STATUS", typeof(string));
                    //table.Columns.Add("PRIORITY CODE", typeof(string));
                    table.Columns.Add("PRIORITY", typeof(string));
                    table.Columns.Add("CASE NUMBER", typeof(string));
                    //table.Columns.Add("COMPLETE", typeof(string));

                    //Create the rows for each splistitem
                    DataRow row;
                    foreach (SPListItem result in results)
                    {
                        row = table.Rows.Add();
                        row["Type"] = result["Type"].ToString();
                        row["Name"] = result["Name"].ToString();
                        row["Modified"] = result["Modified"].ToString();
                        row["Modified By"] = result["Modified By"].ToString();
                        ////row["STATUS"] = result["STATUS"].ToString();
                        ////row["PRIORITY CODE"] = result["PRIORITY CODE"].ToString();
                        row["PRIORITY"] = result["PRIORITY"].ToString();
                        row["CASE NUMBER"] = result["CASE NUMBER"].ToString();
                        ////row["COMPLETE"] = result["COMPLETE"].ToString();
                    }
                    
                    //SPGridView1 = new SPGridView();
                    SPGridView1.Enabled = true;
                    SPGridView1.AutoGenerateColumns = false;
                    SPGridView1.ID = "hotView";

                    SPBoundField HL_TYPE = new SPBoundField();
                    HL_TYPE.HeaderText = "Type";
                    HL_TYPE.DataField = "Type";
                    HL_TYPE.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    HL_TYPE.ItemStyle.Wrap = false;
                    SPGridView1.Columns.Add(HL_TYPE);

                    SPBoundField HL_NAME = new SPBoundField();
                    HL_NAME.HeaderText = "Name";
                    HL_NAME.DataField = "Name";
                    SPGridView1.Columns.Add(HL_NAME);

                    SPBoundField HL_MODIFIED = new SPBoundField();
                    HL_MODIFIED.HeaderText = "Modified";
                    HL_MODIFIED.DataField = "Modified";
                    SPGridView1.Columns.Add(HL_MODIFIED);

                    SPBoundField HL_MODIFIED_BY = new SPBoundField();
                    HL_MODIFIED_BY.HeaderText = "Modified By";
                    HL_MODIFIED_BY.DataField = "Modified By";
                    SPGridView1.Columns.Add(HL_MODIFIED_BY);

                    //SPBoundField HL_STATUS = new SPBoundField();
                    //HL_STATUS.HeaderText = "STATUS";
                    //HL_STATUS.DataField = "STATUS";
                    //SPGridView1.Columns.Add(HL_STATUS);

                    //SPBoundField HL_PRIORITY_CODE = new SPBoundField();
                    //HL_PRIORITY_CODE.HeaderText = "PRIORITY CODE";
                    //HL_PRIORITY_CODE.DataField = "PRIORITY CODE";
                    //SPGridView1.Columns.Add(HL_PRIORITY_CODE);

                    SPBoundField HL_PRIORITY = new SPBoundField();
                    HL_PRIORITY.HeaderText = "PRIORITY";
                    HL_PRIORITY.DataField = "PRIORITY";
                    SPGridView1.Columns.Add(HL_PRIORITY);

                    SPBoundField HL_CASE_NUMBER = new SPBoundField();
                    HL_CASE_NUMBER.HeaderText = "CASE NUMBER";
                    HL_CASE_NUMBER.DataField = "CASE NUMBER";
                    SPGridView1.Columns.Add(HL_CASE_NUMBER);

                    //SPBoundField HL_COMPLETE = new SPBoundField();
                    //HL_COMPLETE.HeaderText = "COMPLETE";
                    //HL_COMPLETE.DataField = "COMPLETE";
                    //SPGridView1.Columns.Add(HL_COMPLETE);

                    this.Controls.Add(new LiteralControl(this.MyProperty));
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

        /// <summary>
        /// Ensures that the CreateChildControls() is called before events.
        /// Use CreateChildControls() to create your controls.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            if (!_error)
            {
                try
                {
                    base.OnLoad(e);
                    this.EnsureChildControls();

                    // Your code here...
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            SPSite mySite = SPContext.Current.Site;
            SPWeb myWeb = SPContext.Current.Web;
            SPList myList = myWeb.Lists["HOTLINE"];

            spDataSource.List = myList;
            SPGridView1.DataSource = spDataSource;
            SPGridView1.DataBind();

            SPGridView1.RenderControl(writer);
        }
        /// <summary>
        /// Clear all child controls and add an error message for display.
        /// </summary>
        /// <param name="ex"></param>
        private void HandleException(Exception ex)
        {
            this._error = true;
            this.Controls.Clear();
            this.Controls.Add(new LiteralControl(ex.Message));
        }
    }
}




Error:

Value does not fall within the expected range. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: Value does not fall within the expected range.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[ArgumentException: Value does not fall within the expected range.]
   Microsoft.SharePoint.SPFieldCollection.GetField(String strName, Boolean bThrowException) +305
   Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException) +77
   Microsoft.SharePoint.SPListItem.GetValue(String strName) +39
   Microsoft.SharePoint.SPListItem.get_Attachments() +278
   Microsoft.SharePoint.WebControls.SPDataSourceViewPropertyDescriptor.GetValue(SPListItem listItem) +401
   Microsoft.SharePoint.WebControls.SPDataSourceViewPropertyDescriptor.GetValue(Object component) +469
   System.Web.UI.WebControls.BoundField.GetValue(Control controlContainer) +192
   System.Web.UI.WebControls.AutoGeneratedField.OnDataBindField(Object sender, EventArgs e) +98
   System.Web.UI.Control.OnDataBinding(EventArgs e) +99
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +155
   System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2002
   Microsoft.SharePoint.WebControls.SPGridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +187
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.WebControls.GridView.DataBind() +4
   HotlineWebPart_WP.HotLine_WebPart.Render(HtmlTextWriter writer) +198
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter output, WebPart part) +66

[WebPartException: Value does not fall within the expected range.]
   Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter output, WebPart part) +140
   Microsoft.SharePoint.WebPartPages.SPChrome.RenderWebPart(HtmlTextWriter output, WebPart part) +63
   Microsoft.SharePoint.WebPartPages.WebPartZone.RenderZoneCell(HtmlTextWriter output, Boolean bMoreParts, WebPart part) +144
   Microsoft.SharePoint.WebPartPages.WebPartZone.RenderWebParts(HtmlTextWriter output, ArrayList webParts) +495
   Microsoft.SharePoint.WebPartPages.WebPartZone.Render(HtmlTextWriter output) +902
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +163
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

Open in new window

0
 
LVL 5

Author Comment

by:Isaac
ID: 35158401
Ok.  I was able to narrow it down by commenting things out.  The problem seems to be the STATUS

When I un-comment the following, that's when I get the error:

//table.Columns.Add("STATUS", typeof(string));

//row["STATUS"] = result["STATUS"].ToString();



Any Ideas?
       //SPBoundField HL_STATUS = new SPBoundField();
                    //HL_STATUS.HeaderText = "STATUS";
                    //HL_STATUS.DataField = "STATUS";
                    //SPGridView1.Columns.Add(HL_STATUS);
0
 
LVL 1

Accepted Solution

by:
ChouhanR earned 500 total points
ID: 35163003
As of now..looking to your code the only thing i think that is causing error is wrong column name that you are trying to access... STATUS.. check its name..


        SPWeb oWebsite = SPContext.Current.Web;
        SPList oList = oWebsite.Lists["List_Name"];
        SPListItemCollection collListItems = oList.Items;
        GridView gv1 = collListItems.GetDataTable();

if you wann try other way.. use above code...
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question