简体   繁体   中英

How windows forms Gridview is different from asp.net gridview?

I am experienced in asp.net and it's tools, i always use gridview to fill it with data from database, i usually edit it in .aspx code and rarely in .cs code but i am newbie to windows forms gridview, how it is different from asp.net's gridview. It doesn't have behind code, can it only be edited from wizard and properties etc or any other way ?

The major difference in ASP.NET databound controls classes from their WinForms counterparts is in the object lifecycle and user interaction.

You can see that DataGridView contains much more methods then GridView.

DataGridView Methods - 400.

GridView Methods - 147.

This is due to the fact that WinForms controls handle user interaction in-process, and are responsible for handling mouse events, keyboard events and dynamic layout manipulation. ASP.NET controls are usually limited to what can be implemented with renderd HTML. As a basic feature, Javascript is only used when it's absolutely needed for WebForms functionality, such as postbacks and partial update panels. Consider the following method in DataGridView: AutoResizeRow(Int32). There's no such method the ASP.NET's GridView, because this kind of method would require javascript manipulation that is too much related to the HTML rendering engine in browsers. The same applies to mouse and keyboard events.

As for data manipulation methods, ASP.NET databound controls contain pretty much the same set of functionality. The difference here is that data must be manipulated out-of-process, and the controls state must be serialized so it could be restored back before handling postback events on server side.

ASP.NET requires control instances to be recreated each time a server side event occurs. That is why ASP.NET GridView contains {Load,Save}{ViewState,ControlState} methods.

In WinForms, on the contrary, only a single control instance is needed the same part of view. The state lives in-process and does not need to be serialized.

As for the designer support and codebehind - it works pretty much the same way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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