Thursday, April 25, 2013

Bind data to datalist in

Title:How to bind data to data list in using

In previous post we have seen bind data to grid view,bind xml data to grid view in this post i will show how to bind the data to data list using SQL Data source in we don't need write the code to get the data for data list
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<script src="" type="text/javascript"></script>
<form id="form1" runat="server">
<asp:DataList ID="DataList1" runat="server" Font-Size="10pt" Width="350px" HeaderStyle-BackColor="ActiveBorder"
 AlternatingItemStyle-BackColor="Aqua" DataSourceID="SqlDataSource1">
Order Details
OrderID: &nbsp;<asp:Label ID="OrderIDLabel" runat="server" Text='<%# Eval("OrderID") %>' />
<asp:Label ID="OrderNameLabel" runat="server" Text='<%# Eval("OrderName") %>' />
<asp:Label ID="PhoneLabel" runat="server" Text='<%# Eval("Phone") %>' />
<asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("Address") %>' />
<asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="SELECT * FROM [Orders]"></asp:SqlDataSource>
1.Select data source for data list using options
Design mode ->Data list Tasks->choose new data source
2.Select the SQL Data Source->click next
3.Create new connection wizard will open.In this we have make select the new connection button.
4.Select the data base which you want to use on next then get wizard to configure the data using query. finish

Post a Comment