當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' –