Replies
Thanks Lyuba!!
Yes earlier I was using 10.2 version but Now I am using 10.1 version. It's working fine with 10.1 version.
I created a similar example based on the on demand example shared in this thread. But I am getting strange error while expanding the nodes.
public
partial class CustomWebHierarchicalGrid : System.Web.UI.
Page
{
public void whdg1_PreRender(object sender, EventArgs
e)
{
if
(!IsPostBack)
{
foreach (ContainerGridRecord row in
whdg1.GridView.Rows)
{
row.IsEmptyParent =
true
;
}
}
}
public void whdg1_InitializeRow(object sender, RowEventArgs
e)
{
// don't show the arrow for the last level
if (((ContainerGridRecord
)e.Row).Level < 3)
((
ContainerGridRecord)e.Row).IsEmptyParent = true
;
}
private void
BindGrid()
{
DataSet ds = new DataSet
();
ds.Tables.Add(
"Categories"
);
ds.Tables[
"Categories"].Columns.Add("CategoryID"
);
ds.Tables[
"Categories"].Columns.Add("CategoryName"
);
ds.Tables[
"Categories"].Rows.Add("1", "A"
);
ds.Tables[
"Categories"].Rows.Add("2", "B"
);
ds.Tables[
"Categories"].Rows.Add("3", "C"
);
List<Category> list = new List<Category
>();
foreach (DataRow dr in
ds.Tables[0].Rows)
{
list.Add(
new Category { CategoryName = dr.ItemArray[1].ToString(), CategoryID = Int32
.Parse(dr.ItemArray[0].ToString()) });
}
whdg1.DataSource = list;
}
private void BindSecondLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs
e)
{
// Get the data key
int key = (int
)e.Row.DataKey[0];
DataSet ds = new DataSet
();
ds.Tables.Add(
"Products"
);
ds.Tables[
"Products"].Columns.Add("ProductID"
);
ds.Tables[
"Products"].Columns.Add("ProductName"
);
ds.Tables[
"Products"].Rows.Add("1", "PA"
);
ds.Tables[
"Products"].Rows.Add("2", "PB"
);
ds.Tables[
"Products"].Rows.Add("3", "PC"
);
// Create Container Grid
ContainerGrid childGrid = new ContainerGrid
();
e.Row.RowIslands.Add(childGrid);
// Bind Grid
childGrid.DataKeyFields =
"ProductID"
;
childGrid.Level = 1;
childGrid.DataSource = ds.Tables[
"Products"
];
childGrid.DataBind();
}
private void BindThirdLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs
e)
{
// Get the data key
int key = (int
)e.Row.DataKey[0];
DataSet ds = new DataSet
();
ds.Tables.Add(
"OrderDetails"
);
ds.Tables[
"OrderDetails"].Columns.Add("OrderID"
);
ds.Tables[
"OrderDetails"].Columns.Add("Quantity"
);
ds.Tables[
"OrderDetails"].Rows.Add("1", "10"
);
ds.Tables[
"OrderDetails"].Rows.Add("2", "20"
);
ds.Tables[
"OrderDetails"].Rows.Add("3", "30"
);
// Create Container Grid
ContainerGrid childGrid = new ContainerGrid
();
e.Row.RowIslands.Add(childGrid);
childGrid.
// Bind Grid
childGrid.DataKeyFields =
"OrderID"
;
childGrid.Level = 2;
childGrid.DataSource = ds.Tables[
"OrderDetails"
];
childGrid.DataBind();
}
public void whdg1_RowIslandsPopulating(object sender, ContainerRowCancelEventArgs
e)
{
//Cancel the default automatic load on demand operation
e.Cancel =
true
;
switch
(e.Row.Level)
{
case
0:
BindSecondLevel(e);
break
;
case
1:
BindThirdLevel(e);
break
;
}
}
protected void Page_Load(object sender, EventArgs
e)
{
BindGrid();
}
}
public
class
Category
{
public int CategoryID { get; set
; }
public string CategoryName { get; set
; }
aspx
<
form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<ig:WebHierarchicalDataGrid DataKeyFields="CategoryID" ID="whdg1" runat="server" Height="350px"
Width="100%" oninitializerow="whdg1_InitializeRow" AutoGenerateBands="false" InitialExpandDepth="0" InitialDataBindDepth="0"
onprerender="whdg1_PreRender"
onrowislandspopulating="whdg1_RowIslandsPopulating">
</ig:WebHierarchicalDataGrid>
</div>
</form>
I am getting following error on expanding the 2nd level grid
—————————
Message from webpage
—————————
[NullReferenceException]: Object reference not set to an instance of an object.
at Infragistics.Web.UI.GridControls.ContainerGrid.RaisePostDataChangedEvent()
at System.Web.UI.Page.RaiseChangedEvents()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
[HttpUnhandledException]: Exception of type 'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.customwebhierarchicalgrid_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\a052194a\ed07ab01\App_Web_c4nk_s-e.0.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
—————————
OK
—————————