开发者

How can I refresh gridview in ASP.NET C# after Ajax call and executing static method?

开发者 https://www.devze.com 2023-01-05 00:26 出处:网络
I need to refresh data in GridView after I c开发者_高级运维all static method (Asp.Net, C#). Is it possible to accomplish it?well, you can rebind the dataset/datatable you got to the gridview like thi

I need to refresh data in GridView after I c开发者_高级运维all static method (Asp.Net, C#).

Is it possible to accomplish it?


well, you can rebind the dataset/datatable you got to the gridview like this,

myGridViewId.DataSource = myDataTable;
myGridViewId.DataBind();

EDIT: After seeing the comment:You mean with out submitting the form manually ,you can trigger it with the following javascript code..

<script type="text/javascript">
setTimeout(function(){window.location.reload(true);},timeoutPeriod);
//timeoutPeriod in milli seconds..
</script>


I know I am grave digging but I had to do this and I had one heck of a time finding an answer that was satisfactory.

If I am reading the question correctly you have a girdview that is to be 'refreshed' after you complete some call to the server.

So I assume you are doing something where you are making changes to a grid's datasource and then need to reflect those changes to the client by changing the grid they are looking at.

I found this great article where they are discussing building a gridview on the fly. "Using Ajax to create a gird view"

I found the methodology was what I needed except the datasource was not what I needed and it did not go into detail about how you would format anything in that grid (because nothing was there to start).

So I took that example and created a web method where I got my data. I then on the server side added the data into a different datatable that contained only the strings I needed, after manipulating it, and passed it back to the page.

then using some of the jQuery in that article, I was able to 're-bind' or more factually rebuild the grid.

The drawbacks with this are that you are not going to be able to manipulate your data in your aspx page. This method is dependent on a 'template' row existing. The grid I was managing did not need to have data from the start, so this was fine for me. if it did need data at the start in document ready I would have needed to add a call to my method to update the grid.

I hope this helps someone else.

0

精彩评论

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