Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
"Object reference not set..." when clicking on row in an async postback
posted

Hi all,

I'm using a WebHierarchicalDataGrid in NetAdvantage 2010.2.  When I click on a row, I can get to a server-side method using the AutoPostBackFlags feature.  But I continuously get the following when I click on a child-row: 

NullReferenceException: Object reference not set to an instance of an object.] 

The full stack trace is:

[NullReferenceException: Object reference not set to an instance of an object.]

Infragistics.Web.UI.Framework.RunBot.RenderPageCallBack(HtmlTextWriter writer, Control control) +50

System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256

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

Because I've gone back and forth with this, I made a real simple page to display this issue.  I'd like to use this control but it's a hard sell when I can't react to a click on the server side.  Can anyone help me with this?

Thanks,

Bill

 

Here is the aspx page:

<%

@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestGridRowClick.aspx.cs" Inherits="testProject.TestGridRowClick" %>

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

 

html xmlns="http://www.w3.org/1999/xhtml" >

<

 

head runat="server">

 

<title>Untitled Page</title>

</

 

head>

<

 

body>

 

<form id="form1" runat="server">

 

<asp:ScriptManager ID="ScriptManager1" runat="server">

 

</asp:ScriptManager>

 

<div>

 

<ig:WebHierarchicalDataGrid ID="whdg1" runat="server" DataSourceID=""

 

AutoGenerateColumns="false" AutoGenerateBands="false" InitialExpandDepth="0"

 

InitialDataBindDepth="-1" Height="350" Width="100%" DataKeyFields="ID"

 

ExpandableAreaCssClass="ighg_FeatureBrowserExpandableArea" EnableViewState="true" EnableAjax="true" EnableAjaxViewState="true"

 

MaxDataBindDepth="5"

 

OnRowSelectionChanged="whdg1_RowSelectionChanged"

 

>

 

<ExpandCollapseAnimation SlideOpenDirection="Auto" SlideOpenDuration="0" SlideCloseDirection="Auto"

 

SlideCloseDuration="0" />

 

<Columns>

 

<ig:BoundDataField DataFieldName="SubordinateItem" Key="SubordinateItem" Header-Text="Item" Width="10%"/>

 

<ig:BoundDataField DataFieldName="SubordinateName" Key="SubordinateName" Header-Text="Item Name" Width="90%" />

 

</Columns>

 

<Behaviors>

 

<ig:VirtualScrolling Enabled="true" RowCacheFactor=".5" ScrollingMode="Deferred"></ig:VirtualScrolling>

 

<ig:Selection Enabled="true" CellClickAction="Row" RowSelectType="Single">

 

<AutoPostBackFlags RowSelectionChanged="true" />

 

</ig:Selection>

 

</Behaviors>

 

<Bands>

 

<ig:Band DataMember="itemRollupSource_DefaultView" Key="ID" ShowHeader="true"

 

ShowFooter="false" IsSelfReference="true" AutoGenerateColumns="false" >

 

<Columns>

 

<ig:BoundDataField DataFieldName="SubordinateItem" Key="SubordinateItem" Header-Text="Item" Width="10%"/>

 

<ig:BoundDataField DataFieldName="SubordinateName" Key="SubordinateName" Header-Text="Item Name" Width="90%" />

 

</Columns>

 

</ig:Band>

 

</Bands>

 

</ig:WebHierarchicalDataGrid>

 

<ig:WebHierarchicalDataSource ID="itemRollupSource" runat="server">

 

<DataRelations>

 

<ig:DataRelation ChildColumns="SubordinateParentItem" ChildDataViewID="itemRollupSource_DefaultView"

 

ParentColumns="SubordinateItem" ParentDataViewID="itemRollupSource_DefaultView" />

 

</DataRelations>

 

<DataViews>

 

<ig:DataView ID="itemRollupSource_DefaultView" />

 

</DataViews>

 

</ig:WebHierarchicalDataSource>

 

</div>

 

</form>

</

 

body>

</

 

html>

Here is my code-behind:

using

 

System;

using

 

System.Collections;

using

 

System.Configuration;

using

 

System.Data;

using

 

System.Linq;

using

 

System.Web;

using

 

System.Web.Security;

using

 

System.Web.UI;

using

 

System.Web.UI.HtmlControls;

using

 

System.Web.UI.WebControls;

using

 

System.Web.UI.WebControls.WebParts;

using

 

System.Xml.Linq;

using

 

System.Collections.Generic;

namespace

 

testProject

{

 

public partial class TestGridRowClick : System.Web.UI.Page

{

 

protected void Page_Load(object sender, EventArgs e)

{

}

 

protected void Page_Init(object sender, EventArgs e)

{

BindGrid();

}

 

protected List<myHierarchy> _getSampleData()

{

 

List<myHierarchy> resultList = new List<myHierarchy>();

resultList.Add(

new myHierarchy(){ID=1, TopLevelItem="x", SubordinateParentItem=null, SubordinateItem="x", SubordinateName="X Name"});

resultList.Add(

new myHierarchy() { ID = 2, TopLevelItem = "x", SubordinateParentItem = "x", SubordinateItem = "x1", SubordinateName = "X1 Child Name" });

resultList.Add(

new myHierarchy() { ID = 3, TopLevelItem = "x", SubordinateParentItem = "x", SubordinateItem = "x2", SubordinateName = "X2 Child Name" });

resultList.Add(

new myHierarchy() { ID = 4, TopLevelItem = "x", SubordinateParentItem = "x", SubordinateItem = "x3", SubordinateName = "X3 Child Name" });

resultList.Add(

new myHierarchy() { ID = 5, TopLevelItem = "x", SubordinateParentItem = "x3", SubordinateItem = "x31", SubordinateName = "X31 Child Name" });

 

return resultList;

}

 

public void BindGrid()

{

 

string currentItem = "x";

 

 

List<myHierarchy> listResult = _getSampleData();

Infragistics.Web.UI.DataSourceControls.

DataView view = itemRollupSource.DataViews.FindByID("itemRollupSource_DefaultView");

 

if (view == null)

{

view =

new Infragistics.Web.UI.DataSourceControls.DataView();

view.ID =

"itemRollupSource_DefaultView";

itemRollupSource.DataViews.Add(view);

}

view.DataSource = listResult;

whdg1.DataSourceID =

"itemRollupSource";

}

 

protected void whdg1_RowSelectionChanged(object sender, Infragistics.Web.UI.GridControls.SelectedRowEventArgs e)

{

Infragistics.Web.UI.GridControls.

SelectedRowCollection src = e.CurrentSelectedRows;

 

if (src.Count > 0)

{

 

string itemSelected = src[0].Items[0].Text;

}

 

// fill another grid

}

}

 

public class myHierarchy

{

 

public int ID {get; set;}

 

public string TopLevelItem {get; set;}

 

public string SubordinateParentItem {get; set;}

 

public string SubordinateItem {get; set;}

 

public string SubordinateName {get; set;}

}

 

 

 

}