Listing Records in Database Using GridView and SqlDataSource

Connecting to Access Database and Listing Records in GridView Using SqlDataSource

  1. Create your database with mdb extension (Access 2000) in Access program.
  2. Create the necessary tables and fields in it according to your needs.
  3. If there is no App_Data folder on your website, add this folder from the Solution Explorer panel. ( Right click on the site name – Add – Add Asp.Net Folder – App_Data ) Place the database file in this folder.
  4. Add an SqlDataSource object to your page from the Data category in the Toolbox.

asp.net sqldatasource veritabanı

  1. Click the "Configure Data Source" command from the tasks section to the right of the SqlDataSource object you added.
  2. The DataSource configuration wizard will run.

asp.net sqldatasource connection

  1. İlk adımda kullanılacak olan bağlantı nesnesini seçmeniz istenecektir. Kullanacağınız veritabanı listede görünüyorsa onu seçiniz. Eğer görünmüyorsa “New Connection” butonuna tıklayarak veritabanı özelliklerini (Microsoft Access … OLE DB) ve yerini belirtiniz. Ardından Next butonuna tıklayınız.

asp.net save connection web config

  1. In this step, if the connection you just specified is not registered, you will be asked if you want to save it. If you save it by giving a name, the connection properties will be written to the web.config file, and it will be taken from there in the next times. If you selected an already registered connection in the first step, this screen will not appear.

asp.net sqldatasource configure select statement

  1. In the next window, the tables in the selected database will be listed. We can create the Select query by selecting the desired table and marking the desired fields from that table. Optionally;
    • You can set the sorting method by clicking the Order By button,
    • By clicking the Where button, you can determine the filter to be applied to the records,
    • By clicking the Advance button, we can enable the automatic creation of Insert, Update and Delete commands.
  2. In the last step that will be opened by clicking the Next button, we can check the operation of the connection and query by clicking the Test button.
  3. When we click the Finish button, our SqlDataSource object will now be configured.
  4. We can also use ready-made objects such as GridView, ListView, FormView, DetailsView so that the data to be accessed with SqlDataSource can be displayed on the page.
  5. From the data category in the ToolBox, add a GridView control where you want the data to appear.
  6. Select the SqlDataSource object you created from the "Choose Data Source" section in the tasks pane on the right side of the added GridView object.
  7. Thus, the GridView will be bound to that DataSource object and the fields in the GridView will be created automatically. When you test the page by running, you will see that the records are listed on the page in the form of a table.
  8. You can click the Auto Formats command in the tasks pane to change the appearance of the GridView object. You can also make the changes you want from the Properties panel.
  9. Again, by clicking the Edit Columns command in the GridView's tasks pane, you can perform many operations on columns. For example, you can make many settings such as column headings, widths, ordering from here.
  10. Let's briefly explain the other options in the GridView tasks pane:
    • Enable Paging: By checking it, you can make the records appear as pages. With the PageSize property, you can set how many records will appear on each page.
    • Enable Sorting: You can give the user a chance to sort the records. If this option is checked, the user can change the order by clicking the column headers.
    • Enable Selecting: Allows creating a select button for each record, the selected record is displayed more clearly.
    • In order for the following two options to appear, the "Generate INSERT, UPDATE and DELETE statements" option must be checked by clicking the Advance button while configuring the SqlDataSource. If this is not done, the options below will not appear.
    • Enable Deleting: Allows creating a delete button next to each record. The user can delete that record by clicking this button.
    • Enable Editing: An edit button is created next to each record. When the user clicks this button, that row is made editable. If they make changes and click the Update button, the database is updated.
Listing Records in Database Using GridView and SqlDataSource, show data in gridview tutorial, listing data using gridview, using sqldatasource, asp.net database operations with gridview and datasource

EXERCISES

There are no examples related to this subject.



COMMENTS




Read 737 times.

Online Users: 702



listing-records-in-database-using-gridview-and-sqldatasource