HierarGrid and StackOverflow exceptions

HierarGrid and StackOverflow exceptions

If you are running into a StackOverflowException when working with nested grids, you'll need to check the code-behind of the child grid.

Make sure that the databinding code for the DataGrid is located in the Page.DataBind event and not in Page.Load or ChildGrid.DataBind.

In the HierarGrid demo on my homepage this can be seen in the TitleList.ascx.cs/.vb.

C#:
private void InitializeComponent()
{
   ...
   this.DataBinding += new System.EventHandler(this.TitleList_DataBinding);
   //not this.HG1.DataBinding or this.Load
}

private void TitleList_DataBinding(object sender, System.EventArgs e)
{
    DataGridItem dgi = (DataGridItem) this.BindingContainer;
    if(!(dgi.DataItem is DataSet))
        throw new ArgumentException("Please change...");
    DataSet ds = (DataSet) dgi.DataItem;
    HG1.DataSource = ds;
    HG1.DataMember = "Titles";
    HG1.DataBind();

}

VB:
Private Sub TitleList_DataBind(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DataBinding

If you notice any other reason for a StackOverflow exception, please let me know.

原文地址:https://www.cnblogs.com/dimg/p/345850.html