<%@ 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>
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(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)