How to Create DataSource control using Form RepeaterControl in ASP.net


In this article I'm trying to explain how to create DataSource controls like LinqDataSource, XMLDataSource etc.. Using Repeater control in ASP.net. During this process we can able to learn how to create DataSource controls and how to configure with Repeater control for displaying data into that. This article will help you for beginners.

How to Create DataSource control using Form RepeaterControl in ASP.net:



In this article I'm trying to explain how to create DataSource controls like LinqDataSource, XMLDataSource etc.. Using Repeater control in ASP.net. During this process we can able to learn how to create DataSource controls and how to configure with Repeater 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 RCDataSource.aspx.

1

Step-2:



Then open a designer page and simply drag & drop one Repeater 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:



Choose your Data Context object available in dropdown menu and then click on Next button.

4

Step-5:



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.

5

Step-6:



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.

6

Step-7:



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

<asp:Repeater ID="Repeater1" runat="server"

DataSourceID="LinqDataSource1"

>
</asp:Repeater>

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




Step-8:



If you are using Repeater control then you must and should implement the designer page then only you can able to see the output. Just design the page like below.


<table>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="LinqDataSource1">
<HeaderTemplate>
<tr>
<th>
Employee Name
</th>
<th>
Job
</th>
<th>
Departement
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container.DataItem,"Emp_Name") %>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "Emp_job")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "Emp_Dep")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="DataClassesDataContext" EntityTypeName=""
Select="new (Emp_Name, Emp_job, Emp_Dep)" TableName="tblEmployees">
</asp:LinqDataSource>


Step-9:



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

7

Conclusion :



I hope this article will help you those who are looking for the same and those who are new to implement Repeater 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.


Article by naveensanagasetti
I hope you enjoyed to read my article, If you have any queries out of this then please post your comments.

Follow naveensanagasetti or read 139 articles authored by naveensanagasetti

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: