Getting started

The point of this page is to demonstrate the use of C# code inside the ASP.net Framework with examples of The ASP Repeater.

The following Repeater is used to display data from a SQL Database. The disply is formatted in a Bootstrap Table that hides the Country and City columns to make display on a Mobile Device more compact. Clicking on a record in the table will expand the Country and City below. Clicking again will then collapse the record.

ID First Name Last Name
1 Maria Anders
Country: Germany City: Berlin
2 Ana Trujillo
Country: Mexico City: México D.F.
3 Antonio Moreno
Country: Mexico City: México D.F.
4 Thomas Hardy
Country: UK City: London
5 Christina Berglund
Country: Sweden City: Luleå
6 Hanna Moos
Country: Germany City: Mannheim
7 Frédérique Citeaux
Country: France City: Strasbourg
8 Martín Sommer
Country: Spain City: Madrid
9 Laurence Lebihan
Country: France City: Marseille
10 Elizabeth Lincoln
Country: Canada City: Tsawassen
11 Victoria Ashworth
Country: UK City: London
12 Patricio Simpson
Country: Argentina City: Buenos Aires
13 Francisco Chang
Country: Mexico City: México D.F.
14 Yang Wang
Country: Switzerland City: Bern
15 Pedro Afonso
Country: Brazil City: Sao Paulo
16 Elizabeth Brown
Country: UK City: London
17 Sven Ottlieb
Country: Germany City: Aachen
18 Janine Labrune
Country: France City: Nantes
19 Ann Devon
Country: UK City: London
20 Roland Mendel
Country: Austria City: Graz
21 Aria Cruz
Country: Brazil City: Sao Paulo
22 Diego Roel
Country: Spain City: Madrid
23 Martine Rancé
Country: France City: Lille
24 Maria Larsson
Country: Sweden City: Bräcke
25 Peter Franken
Country: Germany City: München
26 Carine Schmitt
Country: France City: Nantes
27 Paolo Accorti
Country: Italy City: Torino
28 Lino Rodriguez
Country: Portugal City: Lisboa
29 Eduardo Saavedra
Country: Spain City: Barcelona
30 José Pedro Freyre
Country: Spain City: Sevilla
31 André Fonseca
Country: Brazil City: Campinas
32 Howard Snyder
Country: USA City: Eugene
33 Manuel Pereira
Country: Venezuela City: Caracas
34 Mario Pontes
Country: Brazil City: Rio de Janeiro
35 Carlos Hernández
Country: Venezuela City: San Cristóbal
36 Yoshi Latimer
Country: USA City: Elgin
37 Patricia McKenna
Country: Ireland City: Cork
38 Helen Bennett
Country: UK City: Cowes
39 Philip Cramer
Country: Germany City: Brandenburg
40 Daniel Tonini
Country: France City: Versailles
41 Annette Roulet
Country: France City: Toulouse
42 Yoshi Tannamuri
Country: Canada City: Vancouver
43 John Steel
Country: USA City: Walla Walla
44 Renate Messner
Country: Germany City: Frankfurt a.M.
45 Jaime Yorres
Country: USA City: San Francisco
46 Carlos González
Country: Venezuela City: Barquisimeto
47 Felipe Izquierdo
Country: Venezuela City: I. de Margarita
48 Fran Wilson
Country: USA City: Portland
49 Giovanni Rovelli
Country: Italy City: Bergamo
50 Catherine Dewey
Country: Belgium City: Bruxelles
51 Jean Fresnière
Country: Canada City: Montréal
52 Alexander Feuer
Country: Germany City: Leipzig
53 Simon Crowther
Country: UK City: London
54 Yvonne Moncada
Country: Argentina City: Buenos Aires
55 Rene Phillips
Country: USA City: Anchorage
56 Henriette Pfalzheim
Country: Germany City: Köln
57 Marie Bertrand
Country: France City: Paris
58 Guillermo Fernández
Country: Mexico City: México D.F.
59 Georg Pipps
Country: Austria City: Salzburg
60 Isabel de Castro
Country: Portugal City: Lisboa
61 Bernardo Batista
Country: Brazil City: Rio de Janeiro
62 Lúcia Carvalho
Country: Brazil City: Sao Paulo
63 Horst Kloss
Country: Germany City: Cunewalde
64 Sergio Gutiérrez
Country: Argentina City: Buenos Aires
65 Paula Wilson
Country: USA City: Albuquerque
66 Maurizio Moroni
Country: Italy City: Reggio Emilia
67 Janete Limeira
Country: Brazil City: Rio de Janeiro
68 Michael Holz
Country: Switzerland City: Genève
69 Alejandra Camino
Country: Spain City: Madrid
70 Jonas Bergulfsen
Country: Norway City: Stavern
71 Jose Pavarotti
Country: USA City: Boise
72 Hari Kumar
Country: UK City: London
73 Jytte Petersen
Country: Denmark City: Kobenhavn
74 Dominique Perrier
Country: France City: Paris
75 Art Braunschweiger
Country: USA City: Lander
76 Pascale Cartrain
Country: Belgium City: Charleroi
77 Liz Nixon
Country: USA City: Portland
78 Liu Wong
Country: USA City: Butte
79 Karin Josephs
Country: Germany City: Münster
80 Miguel Angel Paolino
Country: Mexico City: México D.F.
81 Anabela Domingues
Country: Brazil City: Sao Paulo
82 Helvetius Nagy
Country: USA City: Kirkland
83 Palle Ibsen
Country: Denmark City: Århus
84 Mary Saveley
Country: France City: Lyon
85 Paul Henriot
Country: France City: Reims
86 Rita Müller
Country: Germany City: Stuttgart
87 Pirkko Koskitalo
Country: Finland City: Oulu
88 Paula Parente
Country: Brazil City: Resende
89 Karl Jablonski
Country: USA City: Seattle
90 Matti Karttunen
Country: Finland City: Helsinki
91 Zbyszek Piestrzeniewicz
Country: Poland City: Warszawa

The following code is the Page_Load Event that looks up the value in the database and places it into the Repeater:

private String dbConnection = ConfigurationManager.ConnectionStrings["MYCONNECTIONSTRING"].ConnectionString;
   protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           BindData();
       }
   }
 
   private void BindData()
   {
       try
       {
           string strQuery = "SELECT Customers.* FROM Customers";
           SqlCommand cmd = new SqlCommand(strQuery);
           Repeater1.DataSource = GetData(cmd);
           Repeater1.DataBind();
           
       }
       catch
       {
           ScriptManager.RegisterStartupScript(this, GetType(), "showalert""alert('There was an Error accessing the Database');"true);
       }
   }
 
   private DataTable GetData(SqlCommand cmd)
   {
       DataTable dt = new DataTable();
       SqlConnection con = new SqlConnection(dbConnection);
       SqlDataAdapter sda = new SqlDataAdapter();
       cmd.CommandType = CommandType.Text;
       cmd.Connection = con;
       con.Open();
       sda.SelectCommand = cmd;
       sda.Fill(dt);
       return dt;
   }

}