所有,我正在使用该事件来RowCreated填充每个Row. GridView但是我发现每当我单击任何可能触发页面回发的服务器控件时都会触发RowCreated事件。这将导致不可用(null)的问题。GridViewAsp.net Buttone.Row.DataItem
代码如下所示。
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
SomeObject mapItem = (SomeObject)e.Row.DataItem;//DataItem is null when postback.
}
}
而且我确信我没有绑定任何东西DataTable或List<T>使用GridViewwhen 回发。经过研究。我还发现如果我将代码移动到RowDataBound事件。一切都好。问题消失了。我只是不知道为什么。希望可以有人帮帮我。谢谢。