简体   繁体   English

插入后更新GridView

[英]Updating GridView after insert

We are using Visual Studio 2010 and .NET 4.0 for an ASP.NET website and MVC for the general architecture. 我们将Visual Studio 2010和.NET 4.0用于ASP.NET网站,将MVC用于常规体系结构。

There are 2 parts to this question. 这个问题分为两部分。 Nothing is on how to do this but what is the right way as per good design and industry standards. 什么都没有做,但是按照好的设计和行业标准,正确的方法是什么。

  1. If I have a GridView (AJAX enabled) with 1000 + records (lot of data), and show 100 records at a time, do I go back to database for next 100 records, or store the data in session and just rebind the gridview by taking new data from session? 如果我有一个GridView(启用AJAX),具有1000条以上的记录(大量数据),并且一次显示100条记录,那么我是否要返回数据库以获取下100条记录,还是将数据存储在会话中,然后重新绑定gridview?从会话中获取新数据?

  2. In the case of an insert, I have 2 choices. 在插入的情况下,我有2个选择。 One, insert a record in the database and reload the gridview and rebind. 一种,在数据库中插入一条记录,然后重新加载gridview并重新绑定。 Two, insert record in session and database and update the GridView based on session data. 二,在会话和数据库中插入记录,并根据会话数据更新GridView。 I need not download new data from database. 我不需要从数据库下载新数据。

Can you please point me in right direction? 能给我指出正确的方向吗?

Forget the 1000 records at a time... If you're only showing 100 at a time, that's all you need to worry about. 一次忘记1000条记录...如果一次只显示100条,这就是您所需要担心的。 In my opinion, requery the database. 我认为,请重新查询数据库。 100 records at a time isn't much. 一次100条记录并不多。 Don't rely on session for this sort of thing, embrace the 'stateless' nature of the web. 不要依靠会话来完成这类事情,而应该拥抱网络的“无状态”本质。

I don't think using session gives you much benefit. 我认为使用会话不会给您带来太多好处。 Either way, the info needs to be sent to the user's browser. 无论哪种方式,都需要将信息发送到用户的浏览器。 Querying the database for 100 records is probably a trivial operation (in terms of latency). 在数据库中查询100条记录可能很简单(就延迟而言)。 From a development standpoint, the added complexity of introducing session state here isn't worth it. 从开发的角度来看,在此处引入会话状态增加的复杂性是不值得的。 (Ask yourself, exactly what benefit does session give you here?) (问问自己,会议在这里给您带来了什么好处?)

That's just my opinion, others may differ. 那只是我的意见,其他人可能会有所不同。 But I can't imagine running into too many problems querying for 100 records at a time in this scenario 但是我无法想象在这种情况下一次查询100条记录会遇到太多问题

Read this article from ScottGu. 阅读ScottGu的这篇文章。 Page your recordsets at the database. 在数据库上分页记录集。 In most cases this is the correct approach. 在大多数情况下,这是正确的方法。 The article shows some benchmarks. 本文显示了一些基准。 If your site becomes high traffic, storing in session can be resource intensive. 如果您的站点流量很高,则会话中的存储可能会占用大量资源。 If you were to scale to a webfarm, you'd likely end up storing session state in sql server anyway. 如果要扩展到Webfarm,则无论如何都可能最终将会话状态存储在sql服务器中。

Session data is also volatile. 会话数据也是易变的。 What if the user opens the same page in 2 browser windows? 如果用户在2个浏览器窗口中打开同一页面怎么办? You'll end up stepping on the toes of each page. 您最终将踩到每页的脚趾。 What if the user walks away from the page, letting session or cache expire? 如果用户离开页面,让会话或缓存过期,该怎么办? You'll have the same issues with Cache. 缓存也会遇到相同的问题。

Paging at the server scales the best. 在服务器上分页可最佳扩展。

http://www.4guysfromrolla.com/articles/031506-1.aspx#postadlink http://www.4guysfromrolla.com/articles/031506-1.aspx#postadlink

You can store the data in the cache object at the server to avoid having to read the database each time. 您可以将数据存储在服务器上的缓存对象中,以避免每次都必须读取数据库。 http://msdn.microsoft.com/en-us/library/aa478965.aspx http://msdn.microsoft.com/en-us/library/aa478965.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM