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.

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.

Step-1:



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.

1

Step-2:



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.

2

Step-3:



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.

3

Step-4:



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.

4

Step-5:



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.

5

Step-6:



Just see the code behind how the code looks become changes.

<asp:DataList ID="DataList1" runat="server"

DataSourceID="LinqDataSource1"

>
<ItemTemplate>
Emp_Name:
<asp:Label ID="Emp_NameLabel" runat="server" Text='<%# Eval("Emp_Name") %>' />
<br />
Emp_job:
<asp:Label ID="Emp_jobLabel" runat="server" Text='<%# Eval("Emp_job") %>' />
<br />
Emp_Dep:
<asp:Label ID="Emp_DepLabel" runat="server" Text='<%# Eval("Emp_Dep") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>

<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="DataClassesDataContext" EntityTypeName=""
Select="new (Emp_Name, Emp_job, Emp_Dep)" TableName="tblEmployees">
</asp:LinqDataSource>




Step-7:



Now the times to execute the code in browser just press F5 on your keyboard and see the result.

6

Conclusion :



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.

About Author:



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.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: