为什么递归网格绑定会导致中的堆栈溢出.NET



此代码递归绑定gridview,导致堆栈溢出问题,错误为:"线程用完了它的堆栈";。

protected override void OnLoad(EventArgs e)
{
if (NavHandler.InSecurityManager) return;
//Profile the start and stop of the linq call
LinqDS.Selecting += delegate { StepSelecting = MiniProfiler.Current.Step("Grid: " + ID + " - Select"); };
LinqDS.Selected += delegate { if (StepSelecting != null) StepSelecting.Dispose(); };
//...and the databind
DBG.DataBinding += delegate { StepDatabind = MiniProfiler.Current.Step("Grid: " + ID + " - Databind"); };
DBG.DataBound += delegate { if (StepDatabind != null) StepDatabind.Dispose(); };
}
protected void DBG_DataBound(object sender, EventArgs e)
{
PageControls.Visible = DBG.PageCount > 1;
if (!IsPostBack)
{
var key = GridKey;
var page = Session[key] != null ? (int)Session[key] : 0;
SetPage(page);
}
}
private void SetPage(int page)
{
DBG.PageIndex = page;
Session[GridKey] = page;
}

请在下面找到绑定相关代码

public event EventHandler DataBound
{
add { DBG.DataBound += value; }
remove { DBG.DataBound -= value; }
}

SetPage((导致绑定方法触发,从而触发SetPage(,依此类推

最新更新