当button_click
事件被触发时。我从方法中获得DataTable
,并将其分配给在类中定义的DataTable
,但是这个设置为DataTable
。如果我绑定DataTable
到GridView
它显示数据。DataTable未分配
public partial class Default : System.Web.UI.Page
{
TestClass test = new TestClass();
DataTable _table = new DataTable();
protected void Button1_Click(object sender, EventArgs e)
{
_table = test.getTable();
//displaying table
GridView1.DataSource= _table;
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
//does not displaying table
GridView2.DataSource= _table;
GridView2.DataBind();
}
}
当我想从_table
得到一些数据时,它什么也没有。怎么了?
更新: 感谢所有,特别是Darren Davies,问题在回发。当Button2_Click事件发生时_table分配_table = new DataTable(),因此_table不再引用由方法getTable()返回的表。
确定getTable()返回数据? –
我调试它和_table哈哈ve行[count = 54],但然后我单击button2行有count = 0. –
@AlbertGore - 最有可能发生回发。你需要再次调用'getTable' –