April 22, 2011| | 0 Comment
DataList Control in ASP.NET using Wizard
Programming Level : Beginner
Programming Environment : Visual Studio 2008
Language : Visual C# 2008
In this Article, we are taking Overview of DataList Control in ASP.NET.
- The DataList Web server control displays rows of database information in a customizable format. The format for displaying the data is defined in templates
- The DataList control is useful for data in any repeating structure, such as a table.
- The DataList control can display rows in different layouts, such as ordering them in columns or rows.
- The DataList control renders items in a list using HTML table elements.
Now Follow the Below Steps to Use DataList Control Through Wizard……….
- Create new Website in Visual Studio.
File à New Web Site … (‘New Web Site’ Dialog Box will appear.)
- Set the Language to “Visual C#” or “Visual Basic” in ‘New Web Site’ Dialog Box.
- Now, Open “Default.aspx” file appeared in Solution Explorer.
- Drag the DataList Control from Tool Box onto the Default.aspx (Design).
Figure 1: Drag the DataList Control to the Default.aspx File
- Now, select the <New Data Source> option from DataList Taks.
Figure 2: Selecting Data Source
- Select Data Source Type and Specify the ID for it. Then click OK Button.
- Choose Data Connection to connect with Database Then click Next Button.
- Now, select the Table Name and Column(s) to be display on DataList, Then Click Next Button.
- If you want to verify the Select Statement, Click Test Query Button.
After Click Finish Button, you’ll see the changes in DataList Control as follows
10. Now, if you want to change the Display color of DataList, click the Auto Format… option present in the DataList Tasks and change the Color.(Optional)
- We can also Use the Templates provided by DataList Control, templates are as follows (Optional) :-
Note: Default Template for DataList is ItemTemplate
12. For now I have formatted DataList as Follows:-
- Now, Run the Project by pressing function key
F5 (Run with Debugging)
Ctrl+F5 ( Run without Debugging)
- Result will be displayed in Default Web Browser as follows:-
If you want to avoid the selection of Data Source and formatting the DataList Items through Wizard, then SKIP the Steps 5 to 12.
Instead of Performing Steps 5 to 12, you can also simply type the code for different templates provided by DataList Control into the Source Section of the Default.aspx.