开发者

How to have a DataTable's contents survive the end of a scope?

I've got a DataTable which is declared at the beginning of my class like so:

private DataTable table = new TestData().FillTable();

Throughout the class, I'm able to access the table's contents.

However, I've got a GridView sorting event which changes the contents of the DataTable. Within the event itself, the contents is changed and I've confirmed this through debugging. However, if I call the table from anywhere outside of this method, the contents of the DataTable remains as it was before, i.开发者_高级运维e. the new values seem to be erased once the soerting event's scope is over.

Here is the code of my sorting event:

protected void TableGridView_Sorting(object sender, GridViewSortEventArgs e)
    {
        table.DefaultView.Sort = "GroupNumber, " + e.SortExpression + GetSortDirectio(e.SortExpression);
        TableGridView.DataSource = table;
        TableGridView.DataBind();
    }

When I test the table's contents within the above event, the new values seem to be added. However, if I call the table from any other method, the old values are returned.

What can I do to make the table's contents be updated globally, i.e. to the variable declared at the beginning of my class, and not have different states depending on methods?


I've tested this with GridView Sorting event. Leaving sorting event this.table contains sorted values so it works as exptected. Are you sure you are testing your solution in single page request. After PostBack this.table is assigned from TestData().FillTable() again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜