Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
source code datalist is
XML
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    <asp:DataList ID="DataList1" runat="server" BackColor="#CCCCCC"
        BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4"
        CellSpacing="2" ForeColor="Black" GridLines="Both"
        onselectedindexchanged="DataList1_SelectedIndexChanged">
        <FooterStyle BackColor="#CCCCCC" />
        <ItemStyle BackColor="White" />
        <SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <HeaderTemplate>

<tr>
<b>
<th>
emp_id
</th>
<th>

</th>
<th>
emp_add
</th>
<th>
emp_mob
</th>
<th>
salary
</th>
</b>
</tr>
<br />

        </HeaderTemplate>
        <ItemTemplate>
        <tr>
        <th>
        <%#DataBinder.Eval(Container,"DataItem.emp_id") %>
        </th>
         <th>
        <%#DataBinder.Eval(Container,"DataItem.emp_name") %>
        </th>
         <th>
        <%#DataBinder.Eval(Container,"DataItem.emp_add") %>
        </th>
         <th>
        <%#DataBinder.Eval(Container,"DataItem.emp_mob") %>
        </th>
         <th>
        <%#DataBinder.Eval(Container,"DataItem.salary") %>
        </th>
        </tr>
        <br />
        </ItemTemplate>
        <FooterTemplate>
        <tr>
        <td>
        employee record is displayed
        </td>
        </tr>
        </FooterTemplate>
    </asp:DataList>
    </form>
</body>
</html>


and code behind aspx.cs file is
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Configuration;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataReader dr;
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection("Data Source=(local);Initial Catalog=dbemployee;Integrated Security=yes");
        cmd = new SqlCommand("select *from employee", con);
        con.Open();
        dr = cmd.ExecuteReader();
        DataList1.DataSource = dr;
        DataList1.DataBind();
        con.Close(); 
    }  
}
Posted
Updated 30-Aug-12 5:25am
v2
Comments
_Amy 30-Aug-12 7:49am    
Repost of how can i use paging in data list[^].
Try improving the previous question.

set the property Allow Paging to true.And allow the Page Size
 
Share this answer
 
Comments
Rashid Choudhary 31-Aug-12 1:17am    
and then
Go through below link

http://forums.asp.net/t/1108198.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900