Simple Repeater

(ASP.NET)


This is the simple repeater control with headertemplate, itemtemplate, alternatingitemtemplate and footertemplate column types. I applied my custom styles to the repeater.

Default.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        table.hdrcss {
            width:100%;
        }

        tr.rowcss {

            background-color:green;
            color:white;
            font-size:x-large;
            text-align:center;
        }

        tr.altrowcss {

            background-color:orange;
            color:white;
            font-size:x-large;
            text-align:center;
        }

        tr.headercss {

             background-color:lightgray;
            color:black;
            font-size:x-large;
            text-align:center;
        }

        tr.footercss {
              background-color:lightgray;
            color:gray;
            font-size:x-large;
            text-align:center;
        }

        table.hdrcss th {
          
            border:1px solid lightgray;
            font-size:x-large;
          
        }

         table.hdrcss td {
          
            border:1px solid lightgray;
            font-size:x-large;
          
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="rptr_employees" runat="server">
         
   <HeaderTemplate>
              <table class="hdrcss">
                  <thead>
                      <tr class="headercss">
                          <th>
                              <label>Name</label>
                          </th>
                          <th>
                              <label>Age</label>
                          </th>
                          <th>
                              <label>Salary</label>
                          </th>
                      </tr>
                  </thead>
               <tbody>
            </HeaderTemplate>

       
   <%--  <SeparatorTemplate>
                <hr />
            </SeparatorTemplate>--%>
            <ItemTemplate>
          
                   <tr class="rowcss">
                       <td>
                           <label><%# Eval("Name") %></label>
                       </td>
                       <td>
                            <label><%# Eval("Age") %></label>
                       </td>
                       <td>
                            <label><%# Eval("Salary","{0:c}") %></label>
                       </td>
                   </tr>
            
            </ItemTemplate>

          
  <AlternatingItemTemplate>
               
                   <tr class="altrowcss">
                       <td>
                           <label><%# Eval("Name") %></label>
                       </td>
                       <td>
                            <label><%# Eval("Age") %></label>
                       </td>
                       <td>
                            <label><%# Eval("Salary","{0:c}") %></label>
                       </td>
                   </tr>
           
            </AlternatingItemTemplate>

       
   <FooterTemplate>
             <tr class="footercss">
                 <td colspan="3">
                     <label>Total employee records: 3</label>
                 </td>
             </tr>

              </tbody>
              </table>
          </FooterTemplate>

        </asp:Repeater>
    </div>
    </form>
</body>
</html>



Default.aspx.cs file

    protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    rptr_employees.DataSource = GetEmployees();
                    rptr_employees.DataBind();
                }
            }
            catch(Exception)
            { }
        }

        public List<EmployeeModel> GetEmployees()
        {
            var lst = new List<EmployeeModel>
            {
               new EmployeeModel{Name="Tom",Age=20,Salary=15000},
               new EmployeeModel{Name="Ram",Age=25,Salary=20000},
               new EmployeeModel{Name="John",Age=28,Salary=25000}
            };


            //var lst = new List<EmployeeModel>();

            //for (int i = 1; i < 100;i++ )
            //{
            //    lst.Add(new EmployeeModel { Name="Name"+i,Age=i,Salary=i*600 });
            //}


                return lst;
        }
    }

    public class EmployeeModel
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public double Salary { get; set; }
    }


Ratings


Average Rating: 0.00 by 0 users
Giri Prasad
5/3/2014
5/3/2014
Download PDF
Download Project

Comments