-
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.
-
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.
-
When we click the Finish button, our SqlDataSource object will now be configured.
-
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.
-
From the data category in the ToolBox, add a GridView control where you want the data to appear.
-
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.
-
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.
-
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.
-
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.
-
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