aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

wwwSW
Posted by Aamir Hasan   on Thursday, June 3, 2010 Total Views:  

In this tutorial, i will tell you how to bind Repeater using Linq in asp.net. This is my First Example in Viusal Studio 2010 and Framework 4.O.

Overview

  1. Introduction
  2. Where to use Repeater
  3. Create Project
  4. Countries Classes
  5. Repeater Control
  6. Inheritance Hierarchy
  7. Framework version information
  8. Output
  9. Conclusion
  10. Download
  11. Demo

 

Introduction

Basic templated data bound list is called Repeater.In Repeater control you can use markup tags e.g table,tr,td. under the HeaderTemplate table tag <Table> is used. A table row and columns tag <tr>, <td> include ItemTemplate. and at the end of table tag </table> include in the FooterTemplate.Namespace of Repeater is System.Web.UI.WebControls.

Where to use Repeater

When you have to display a data in way like Table , Div Span tags then you have to use Repeater.DataList and Datagrid Automatically genrate HTML Markup according to devloper Specified.

Repeater have five template.

  1. AlternatingItemTemplate
  2. FooterTemplate
  3. HeaderTemplate
  4. ItemTemplate
  5. SeparatorTemplate

Syntax:

<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
            <table>
</HeaderTemplate>
      <ItemTemplate>
            <tr>
               <td>&nbsp;</td>
               </tr>

</ItemTemplate>
<FooterTemplate>
            </table>
</FooterTemplate>
</asp:Repeater>


Create Project

Open your Visual Studio 2010 and Create a Solution by selecting .Net Framework 4.O. Next Right Click on your Solution Explorer at Right top of Visual Studio Window, Now  Create a New web site.

Classess

From Solution Explorer, Right click on your web site and create a App_code folder by selecting  Add asp.net Folder. Create a CountriesBaseClass.cs which has three properties of different type,string and int. as given below.

public class CountriesBaseClass
{    private int _countryId;
     private string _countryName;
     private string _countryCode;
	public CountriesBaseClass()
	{}
    public int CountryID
    {
        get { return _countryId; }
        set { _countryId = value; }
    }
    public string CountryName
    {
        get { return _countryName; }
        set { _countryName = value; }
    }
    public string CountryCode
    {
        get { return _countryCode; }
        set { _countryCode = value; }
    }

Right Click on App_code folder in your project. click on Add New Item a small window will be open as shown below figure.Countries class Will return all countries which will be populated with a number of country Object.


A List<CountriesBaseClass> is instantiated.First List<CountriesBaseClass> will be created. and return the list.

Create a  class instance as given below. Here, I am using a Generics based List collection of type CountriesBaseClass

 

List _Countries = new List
{
   
new CountriesBaseClass { CountryID=1,CountryName= "Afghanistan", CountryCode= "9AF"},
new CountriesBaseClass { CountryID=2,CountryName= "Albania",CountryCode=  "9AL"}, 
new CountriesBaseClass { CountryID=3,CountryName= "Algeria", CountryCode= "9AG"}, 
new CountriesBaseClass { CountryID=4,CountryName=  "Andorra",CountryCode= "9AN"},
new CountriesBaseClass { CountryID= 5,CountryName= "Angola", CountryCode= "9AO"}, 
new CountriesBaseClass { CountryID= 6,CountryName= "Anguilla",CountryCode=  "9AV"}, 
new CountriesBaseClass { CountryID=7,CountryName= "Antigua and Barbuda", CountryCode= "9AC"}, 
new CountriesBaseClass { CountryID=8,CountryName= "Argentina", CountryCode= "9AR"}, 
new CountriesBaseClass { CountryID=9,CountryName= "Ashmore Cartier Islands", CountryCode= "9AT"}, 
new CountriesBaseClass { CountryID=10,CountryName=  "Australia",CountryCode=  "9AS"}, 
new CountriesBaseClass { CountryID= 11,CountryName= "Austria", CountryCode= "9AU"}, 
new CountriesBaseClass { CountryID= 12,CountryName=  "Bahamas, The", CountryCode= "9BF"}, 
new CountriesBaseClass { CountryID= 13,CountryName=  "Bahrain", CountryCode= "9BA"}, 
new CountriesBaseClass { CountryID=14,CountryName=  "Bangladesh",CountryCode=  "9BG"}, 
new CountriesBaseClass { CountryID=15,CountryName=  "Barbados", CountryCode= "9BB"}, 
new CountriesBaseClass { CountryID=16,CountryName=  "Bassa da India", CountryCode= "9BS"}, 
new CountriesBaseClass { CountryID= 17,CountryName=  "Belgium", CountryCode= "9BE"}, 
new CountriesBaseClass { CountryID=18,CountryName=  "Belize", CountryCode= "9BH"}, 
new CountriesBaseClass { CountryID= 19,CountryName=  "Benin", CountryCode= "9DM"}, 
new CountriesBaseClass { CountryID= 20,CountryName=  "Bermuda",CountryCode=  "9BD"}, 
new CountriesBaseClass { CountryID= 21,CountryName= "Bhutan", CountryCode= "9BT"}, 
new CountriesBaseClass { CountryID= 22,CountryName=  "Bolivia",CountryCode=  "9BL"}, 
new CountriesBaseClass { CountryID=23,CountryName=  "Botswana", CountryCode= "9BC"}, 
new CountriesBaseClass { CountryID=24,CountryName=  "Bouvet Island",CountryCode=  "9BV"}, 
new CountriesBaseClass { CountryID= 25,CountryName=  "Brazil", CountryCode= "9BR"}, 
new CountriesBaseClass { CountryID= 26,CountryName=  "British Indian Ocean Territory", CountryCode= "910"}, 
new CountriesBaseClass { CountryID= 27,CountryName=  "British Virgin Islands",CountryCode=  "9VI"}, 
new CountriesBaseClass { CountryID= 28,CountryName=  "Brunei", CountryCode= "9BX"}, 
new CountriesBaseClass { CountryID= 29,CountryName=  "Bulgaria",CountryCode=  "9BU"}, 
new CountriesBaseClass { CountryID= 30,CountryName=  "Burma", CountryCode= "9BM"}, 
new CountriesBaseClass { CountryID= 31,CountryName=  "Burundi", CountryCode= "9BY"}, 
new CountriesBaseClass { CountryID= 32,CountryName=  "Cameroon",CountryCode=  "9CM"}, 
new CountriesBaseClass { CountryID= 33,CountryName=  "Canada",CountryCode=  "9CA"}, 
new CountriesBaseClass { CountryID= 34,CountryName=  "Cape Verde",CountryCode=  "9CV"}, 
new CountriesBaseClass { CountryID= 35,CountryName=  "Cayman Islands",CountryCode=  "90"}, 
new CountriesBaseClass { CountryID= 36,CountryName=  "Central African Republic", CountryCode= "9CT"}, 
new CountriesBaseClass { CountryID=37,CountryName=  "Chad",CountryCode=  "9CD"}, 
new CountriesBaseClass { CountryID=38,CountryName=  "Chile",CountryCode=  "9CI"}, 
new CountriesBaseClass { CountryID= 39,CountryName=  "China",CountryCode=  "9CH"}, 
new CountriesBaseClass { CountryID= 40,CountryName=  "Christmas Island",CountryCode=  "9KT"}
}

 

 

getAllCountries function, Linq Query will return All countries as given Below.

 

public List getAllCountries()
{
var r = from u in _Countries
select u;
return r.ToList();
}

 

HTML Mark Up

Now In Default.aspx Page, Drag and Drop Repeater from Toolbox  as shown in belwo figure.

Server Side Coding

Open your Default.aspx.cs Page, and on Page Load,Create  a Countries Class Object pass getAllCountries Function Pass to  data source  and Bind it as show below.

 

Countries Obj = new Countries();

Repeater1.DataSource = Obj.getAllCountries();

Repeater1.DataBind();

 

Inheritance

System.Web.UI.WebControl.Repeater inherit from System.Web.UI.Control and System.Web.UI.Control inherit from System.Object.


Framework version information

Repeater is support in .Net framework 1.0, 1.1, 2.O, 3.O, 3.5 and 4.O.

Output

Download:

Repeater.rar (129.18 kb)

Demo:

Click here to View online sample.

For More Detail visit msdn

Repeater Class

Category: All | asp.net
Protected by Copyscape Online Plagiarism Tool

Comments (12) -

The holy passion of Friendship is of so sweet and steady and loyal and enduring a nature that it will last through a whole lifetime, if not asked to lend money.

same day payday loan
same day payday loan United States
11/30/2010 8:11:06 PM #

Never put off until tomorrow what you can do the day after tomorrow.

Supra Vaider
Supra Vaider People's Republic of China
12/2/2010 3:00:35 PM #

Williams is always hurt.*_*

borrow money online
borrow money online United States
12/16/2010 8:56:55 PM #

The first and last thing required of genius is the love of truth.

cash get now
cash get now United States
1/5/2011 1:37:06 AM #

In religion and politics, people's beliefs and convictions are in almost every case gotten at second hand, and without examination.

porn videos
porn videos United States
1/31/2011 12:17:05 AM #

Advertising may be described as the science of arresting the human intelligence long enough to get money from it

personal cash loans
personal cash loans United States
2/21/2011 9:46:58 PM #

Every great advance in natural knowledge has involved the absolute rejection of authority.

You can only be young once. But you can always be immature.

jason
jason United States
12/11/2011 3:43:18 PM #

I think  we all realized smart home products and home automation would be big day, but maybe not this popular. Check out http://sabinessmarthome.com for some cool information.

dofus kamas
dofus kamas Principality of Monaco
2/24/2012 5:49:30 PM #

Once you buy http://www.mmoigold.com/gold/Dofus_kamas.html dofus kamas from us, you could http://www.mmoigold.com/gold/Dragon_Nest.html dragon nest gold and enjoy many other items to get the help in our quest so that you can win every battle in game and maximize the gaming life. www.mmoigold.com/gold/Dungeon_Fighter_Online.html dungeon fighter gold gamers can have imaginable interest in buying gold of wow, especially if you are constantly defeated by their enemies in game and couldn’t advance in the http://www.mmoigold.com/gold/Aion_Gold.html aion gold.

The North Face Outlet
The North Face Outlet People's Republic of China
3/7/2012 5:29:54 PM #

What could give you warm in cold winter. moncler jackets are a nice choice. Usually they are expensive, but you could buy moncler jackets at our moncler outlet, all are cheap price and best quality. If you want to a clothing for outdoor sports. The North Face Jackets are very popular. And The most professional must be arcteryx jackets. Of Course, if you want to use it for Skiing, Spyder Jackets are essential.

aion gold
aion gold Australia
3/12/2012 11:24:57 PM #

Once you buy http://www.mmoigold.com/gold/Dofus_kamas.html dofus kamas from us, you could http://www.mmoigold.com/gold/Dragon_Nest.html dragon nest gold and enjoy many other items to get the help in our quest so that you can win every battle in game and maximize the gaming life. www.mmoigold.com/gold/Dungeon_Fighter_Online.html dungeon fighter gold gamers can have imaginable interest in buying http://www.mmoigold.com/gold/Tera_gold.html tera gold of wow, especially if you are constantly defeated by their enemies in http://www.mmoigold.com/gold/Eligium_Gold.html eligium gold and couldn’t advance in the http://www.mmoigold.com/gold/Aion_Gold.html aion gold.

Nike Dunks High
Nike Dunks High People's Republic of China
3/23/2012 12:45:00 AM #

www.cheap-nikedunksb.com/nike-dunks-high-c-79.html    Nike Dunks High
www.cheap-nikedunksb.com/nike-dunks-low-c-74.html     Nike Dunks Low

five fingers shoes
five fingers shoes People's Republic of China
3/26/2012 11:56:20 PM #

GH-Among the vibram five finger, quilted jackets seem to be hogging the limelight at the moment. The skechers shape ups is known for its quality, practicality and style - five fingers vibram quilts give it good insulation for the colder months. skechers shape ups uk come in a variety of colours and styles, some will have http://www.vibram-five-finger.org/ contemporary chest pockets and others have vibram fingers slightly lower down (they usually have extra padding to keep your hands warm during winter). Some of the skechers uk have cord collars to contrast with the Vibram Five Fingers Classic, and all of the jackets have a fully-quilted polyamide lining and Skechers Boiling Point Boots insulation. http://www.skecher-uk.com/

fafafa
fafafa Slovenia
4/23/2012 3:48:03 AM #

http://www.christianlouboutinukk.org   christian louboutin
http://www.tiffanyuks.org   tiffany uk
http://www.gucciukbeltuk.org   gucci belt
http://www.frsaclouisvuittonsac.com   louis vuitton sac
http://www.chanelukoutletuks.org   chanel outlet
http://www.burberryukoutletuk.org   burberry
http://www.poloralphlaurenuko.org   ralph lauren uk

fafafa
fafafa Slovenia
4/23/2012 3:48:26 AM #

http://www.christianlouboutinukk.org   christian louboutin
http://www.tiffanyuks.org   tiffany uk
http://www.gucciukbeltuk.org   gucci belt
http://www.frsaclouisvuittonsac.com   louis vuitton sac
http://www.chanelukoutletuks.org   chanel outlet
http://www.burberryukoutletuk.org   burberry
http://www.poloralphlaurenuko.org   ralph lauren uk

bvlgari assioma 28155
bvlgari assioma 28155 United Kingdom
5/15/2012 10:34:35 PM #

This is a really interesting and informative post.<a href="www.ownreplicawatch.com/...315.html">rolex day date ii replica</a> Good job! keep it up, hope to read your other updates. Thanks for this nice sharing.<a href="www.watchessoul.com/...ca-cb11.html">cheap rolex gmt master</a>

bvlgari assioma 28155
bvlgari assioma 28155 United Kingdom
5/15/2012 10:34:39 PM #

This is a really interesting and informative post.<a href="www.ownreplicawatch.com/...315.html">rolex day date ii replica</a> Good job! keep it up, hope to read your other updates. Thanks for this nice sharing.<a href="www.watchessoul.com/...ca-cb11.html">cheap rolex gmt master</a>

bvlgari assioma 28155
bvlgari assioma 28155 United Kingdom
5/15/2012 10:34:58 PM #

This is a really interesting and informative post.<a href="www.ownreplicawatch.com/...315.html">rolex day date ii replica</a> Good job! keep it up, hope to read your other updates. Thanks for this nice sharing.>

bvlgari assioma 28155
bvlgari assioma 28155 United Kingdom
5/15/2012 10:35:01 PM #

This is a really interesting and informative post.<a href="www.ownreplicawatch.com/...315.html">rolex day date ii replica</a> Good job! keep it up, hope to read your other updates. Thanks for this nice sharing.

bvlgari assioma 28155
bvlgari assioma 28155 United Kingdom
5/15/2012 10:35:14 PM #

This is a really interesting and informative post.<a href="www.ownreplicawatch.com/...315.html">rolex day date ii replica</a> Good job! keep it up, hope to read your other updates. Thanks for this nice sharing.

bvlgari assioma 28155
bvlgari assioma 28155 United Kingdom
5/15/2012 10:35:34 PM #

This is a really interesting and informative post. Good job! keep it up, hope to read your other updates. Thanks for this nice sharing.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5