Bind DataList from database in c#


In this article i will show you how to bind dataList from database table. Also i will give an example of it. In this example i will set the orientation property of items also set columns which is appear on the web page.

The DataList Control

The DataList control is a Data bound control that display data by using templates. These templates define controls and HTML elements that should be displayed for an item. The DataList control exists within the System.Web.UI.WebControl namespace.
Now , lets take an example.

How to bind DataList Control using the SqlDataSource

Follow some steps for binding Datalist to SqlDataSource . Steps same as Previous post. Basically SqlDataSource is used to connect front-end to  back-end using connection string . Connection string  saved in configuration file.
Now , After establishing connection you have to use property builder through ShowSmart tag.

DataList Property builder
Select Property Builder link , Now after selected a new window will open 

dataList Properties

Run You Application

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">


<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:DataList ID="DataList1" runat="server" DataKeyField="Id" DataSourceID="SqlDataSource1" Height="285px" RepeatColumns="3" RepeatDirection="Horizontal" Width="134px">
                <asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>' />
                <br />
                <asp:Label ID="nametLabel" runat="server" Text='<%# Eval("namet") %>' />
                <br />
                <asp:Label ID="IncomeLabel" runat="server" Text='<%# Eval("Income") %>' />
                <br />
<br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [footerex]"></asp:SqlDataSource>

How to use DataList Control in ASP.NET

1 comment: