Thursday, March 15, 2012

ASP.Net Repeater

Repeater can be used for listing data. It can be used to repeat the data horizontally or vertically. And can be used to form s a HTML table and also can be used to prepare a HTML List (LI). For displaying tabular data, we can use the ASP.Net Repeater to form the HTML Table. However when the ASP.Net Repeater is used as a container for controls, It is better to design the templates to be rendered with panels (

) and List Items (
  • The DataList is also works similar to Repeater. But the DataList has some additional ability to perform than ASP.Net Repeater .

    When the page renders, the control loops through the rows in the data source and renders the pre configured template (either in the markup or dynamically configured) for each row. Before and after processing the data items, the ASP.Net Repeater renders the header and the footer based on the configuration of the repeater. Because it has no default appearance, it is can be customized to list any layout and style. For myself if I have planned to work extensively on a page with HTML and strict CSS, I usually go for the ASP.Net Repeater control.

    There are few templates that will be much helpful in repeater. Like other data bound controls Repeater also has some templates to work with. Templates in repeater are not much different from the rest of the Data Bound controls.
    1. ItemTemplate
    2. AlternatingItemTemplate
    3. SeparatorTemplate
    4. FooterTemplate
    5. HeaderTemplate
    There is a special template here introduced is SeparatorTemplate. This template can be used to add some elements between each row like a horizontal line.

    Like other data bound controls, repeater also can be bound with a DataTable. So the procedure is to fetch the data to the DataTable using a SqlClient(if MS SQL server) and Use the SqlDataAdapter to fill it. Then the datatable can be assigned to the DataSource of the repeater. Finally instruct the repeater to bind using DataBind()

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>



    Untitled Page









  • Text='<%# DataBinder.Eval(Container.DataItem, "ProductName")%>'>

    View the original article here

  • No comments:

    Post a Comment