Xem mẫu

  1. Using the Web Forms GridView Control When you looked at accessing databases in previous chapters, you learned how to use the Windows Forms DataGridView control. Web Forms have a similar control called GridView. It has some differences because Microsoft designed it to be used in a Microsoft ASP.NET environment, but the overall purpose is the same; to display and edit rows retrieved from a data source. One difference is related to fetching and displaying large volumes of data. In a Web Forms application, it is very likely that the client application (or the browser) will be remote from the database that is being used. It is imperative that you use network bandwidth wisely (this has been stated several times already, but it is very important and worth repeating), and you should not waste resources retrieving vast amounts of data that the user does not want to see. The Web Forms GridView control supports paging, which allows you to fetch data on demand as the user scrolls up and down through a DataSet. Like the Windows Forms DataGridView control, the Web Forms GridView control is designed to be used while it is disconnected from the database. You can create an SqlDataSource object to connect to a database, populate a DataSet, and then disconnect from the database. You can bind the DataSet in a SqlDataSource control to the GridView control. Unlike a Windows Forms GridView control, the information in a Web Forms GridView control is presented in a grid of read-only text (rendered as an HTML table in the browser). However, properties of the Web Forms GridView control allow a user to enter edit mode, which changes a selected row into a set of text boxes that the user can use to modify the data that is presented. You will use this technique in the exercises in this chapter.  
nguon tai.lieu . vn