【发布时间】:2013-09-28 06:59:14
【问题描述】:
当button_click 事件被触发时。我从方法中得到DataTable 并将其分配给类中定义的DataTable,但是这个DataTable 没有设置。如果我将DataTable 绑定到GridView 它会显示数据。
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 有行 [count = 54],但是我点击 button2 行有 count = 0。
-
@AlbertGore - 很可能发生了回发。您需要再次致电
getTable
标签: c# .net sql-server datatable