Show records from database to listview in web

Posted by Satyapriyanayak under ASP.NET category on | Points: 40 | Views : 877
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<asp:ListView ID="ListView1" runat="server">


<table id="itemPlaceholderContainer" border="1">
<tr runat="server" ID="itemPlaceholder">



<asp:Label ID="lblempid" runat="server" Text='<%# Eval("empid") %>' />



<asp:Label ID="lblempname" runat="server" Text='<%# Eval("empname") %>' />



<asp:Label ID="lblempaddress" runat="server" Text='<%# Eval("empaddress") %>' />


<asp:Label ID="lblempsal" runat="server" Text='<%# Eval("empsal") %>' />


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
SqlConnection con = new SqlConnection(strConnString);
str = "select * from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "employee");
ListView1.DataMember = "employee";
ListView1.DataSource = ds;

Comments or Responses

Login to post response