Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 4518 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > ASP.NET Interview Questions > Explain briefly what is DataList control ...

Explain briefly what is DataList control?

Interview question and answer by: Tripati_tutu | Posted on: 10/15/2010 | Category: ASP.NET Interview questions | Views: 1660 | | Points: 40


Answer:

The DataList control is a data bound list control that displays items using templates. The DataList control supports selecting and editing of data. The contents of the DataList control can be manipulated by using templates. It acts as a container of repeated data items. DataList and GridView Web controls can contain child controls that raise events. Therefore, a DataList control may have a child control as part of a template that raises an event. The child control event is "bubbled up” (sent up) to the control's container. The container control raises an event called RowCommand with parameter values. These values allow one to determine which control raised the original event. One is then able to respond to this event. Alternatively, one can write individual event handlers for the child controls.

• Using the DataSourceID property, binding to data source controls, such as SqlDataSource, ObjectDataSource, and XmlDataSource, is supported
• Using the DataSource property, binding to an object that implements the System.Collections.IEnumerable interface is supported
• DataList supports selecting and editing. Typically, the Repeater is mostly used for displaying data records. However, because of event bubbling, one is able to implement more advanced behavior within a Repeater control.
• The display direction of a DataList control can be vertical or horizontal.
• The layout of the DataList control is controlled with the RepeatLayout property.

List of templates available in DataList:
AlternatingItemTemplate - Works in conjunction with the ItemTemplate to provide a layout for all the odd rows with in the layout.

EditItemTemplate - Allows for a row or item to be defined on how it looks and behaves when editing.

FooterTemplate - Allows the last item in the template to be defined.

HeaderTemplate - Allows the first item in the template to be defined.

ItemTemplate - This is used to define a row or layout for each item in the display.

SelectedItemTemplate - It allows for a row or item to be defined on how it looks and behaves when selected.

SeparatorTemplate - This template is used between the items in the template.

Below there is a sample code to create DataList control.

<asp:DataList ID=" dlMyCountry" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Country_Code") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Country_Name") %>'></asp:Label>
</ItemTemplate>
</asp:DataList>

private void BindGrid()
{
string sql = "Select * from Country Order By Country_Name";
SqlDataAdapter da = new SqlDataAdapter(sql, “Yourconnectionstring”);
DataTable dt = new DataTable();
da.Fill(dt);

dlMyCountry.DataSource = dt;
dlMyCountry.DataBind();
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}

Asked In: Many Interviews | Alert Moderator 
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Tripati_tutu

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/20/2013 2:58:09 AM