Data Source controls are asp .net controls that allow you to connect to a database, retrieve or update data inside the database without writing any code. Thus Data source controls implemented all those downs and ups used in direct data access. More interestingly data source controls work with data oriented list controls (data-bound controls) with ease.
Data source controls handle operations like:
Data source controls handle operations like:
- Managing connection
- Data retrieval and update
- Data presentation etc
- SqlDataSource -used for Sql Server, Oracle, OleDb and ODBC
- AccessDataSource - used for Ms Access
- ObjectDataSource - custom data access class(es)
- XmlDataSource -used for xml files
- SiteMapDataSource - used for sitemap data source
In the above connectionString you provide the name of your connectionString (probably stored inside web.config) like the one I underlined.
Now after this point what is remaining is how to bind to another control that uses the retrieved data and may provide data to update. Let us use a dropdownlist to display the list of departments:
Inside the above markup DataSourceID="SqlDataSource1" is telling the dropdownlist where to find the data while DataTextField="DName" and DataValueField="Dcode" tells which column to use for display text and which one to use for item's value respectively. The AppendDataBoundItems="True" on the other hand dictates the dropdownlist to not only use data from database but also append another additional data to be added at design time or at runtime. Now we've added an item <asp:ListItem Selected="True" Value="Select">Select . . .</asp:ListItem> at design time.
The result should look like: