How to Create DataSource control using DataList control in ASP.net :
In this article I'm trying to explain how to create DataSource controls like LinqDataSource, XMLDataSource etc.. Using Gridview control in ASP.net. During this process we can able to learn how to create DataSource controls and how to configure with DataList control for displaying data into that. This article will help you for beginners.
Follow below steps to achieve your goal.
Design a page by right click on project and then choose Add NewItem option then Choose WebForm and give a name for that as DLDataSource.aspx. Refer below screen shot for more information.
Then open a designer page and simply drag & drop one DataList control to the design view and select the Choose Data Source dropdown and then choose New Data Source option for creating New Data Source control purpose, as shown in below fig.
Once we choose New Data Source option, then a new Data Source Configuration wizard window will appear on the screen. Choose your Data Source type and click on OK button automatically new Data Source control has been created for that control. In below scenario I choose Linq Data Source control.
When I click on Next button its redirect to new window for configure data selection purpose. Choose your table name and then choose columns what do you want to display in output. In the below screen I just choose my table name as Employee and I choose columns are “employee name, job, department", as shown in below fig.
Just click Finish button for creating Data Source control, now it's ready to use that Data Source control while display the information into our Application.
Just see the code behind how the code looks become changes.
<asp:DataList ID="DataList1" runat="server"
<asp:Label ID="Emp_NameLabel" runat="server" Text='<%# Eval("Emp_Name") %>' />
<asp:Label ID="Emp_jobLabel" runat="server" Text='<%# Eval("Emp_job") %>' />
<asp:Label ID="Emp_DepLabel" runat="server" Text='<%# Eval("Emp_Dep") %>' />
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
Select="new (Emp_Name, Emp_job, Emp_Dep)" TableName="tblEmployees">
Now the times to execute the code in browser just press F5 on your keyboard and see the result.
I hope this article will help you those who are looking for the same and those who are new to implement DataList control to configure with Data Source controls.
This is Naveen, I completed my MCA and I have around 3 years of experience in ASP.net while implement Web Applications. For past 3 years I learn no.of Technologies while implement my applications apart from that I try to learn new technologies and I try to implement that while implement my project.