how to display the data in list view,formview details view on a same page in asp.net?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Upendra Pratap ShahiPosted Jul 10, 2015, 2:01 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataControlExp.aspx.cs" Inherits="DataControlExp" %>
DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>title>
head>
<body>
<form id="form1" runat="server">
<div>
<h3>ListViewh3>
<asp:ListView ID="lvCustomers" runat="server" GroupPlaceholderID="groupPlaceHolder1"
ItemPlaceholderID="itemPlaceHolder1" OnPagePropertiesChanging="OnPagePropertiesChanging">
<LayoutTemplate>
<table border="1">
<tr>
<th>Product
th>
<th>Quantity
th>
<th>Price
th>
tr>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1">asp:PlaceHolder>
<tr>
<td colspan="3">
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="lvCustomers" PageSize="10">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true"
ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="false" />
Fields>
asp:DataPager>
td>
tr>
table>
LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1">asp:PlaceHolder>
tr>
GroupTemplate>
<ItemTemplate>
<td>
<%# Eval("Product_Name") %>
td>
<td>
<%# Eval("Quantity") %>
td>
<td>
<%# Eval("Price") %>
td>
ItemTemplate>
asp:ListView>
div>
<br />
<h3>FormViewh3>
<div>
<asp:FormView ID="FormView1" runat="server"
AllowPaging="True" EnableViewState="False" OnPageIndexChanging="FormView1_PageIndexChanging">
<ItemTemplate>
<hr />
<h3><%# Eval("Product_Name") %>h3>
<table border="0">
<tr>
<td class="ProductPropertyLabel">Quantity:td>
<td class="ProductPropertyValue">
<%# Eval("Quantity") %>td>
<td class="ProductPropertyLabel">Price:td>
<td class="ProductPropertyValue">
<%# Eval("Price")%>td>
tr>
table>
<hr />
ItemTemplate>
asp:FormView>
div>
<br />
<h3>DetailsViewh3>
<div>
<div>
<asp:DetailsView ID="DetailsView1" OnPageIndexChanging="DetailsView1_PageIndexChanging"
AllowPaging="true" runat="server" />
div>
div>
form>
body>
html>
DataControlExp.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class DataControlExp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindListView();
BindFormView();
BindDetailsView();
}
}
protected void BindListView()
{
DataSet ds = new DataSet();
DataTable dt;
DataRow dr;
DataColumn pName;
DataColumn pQty;
DataColumn pPrice;
int i = 0;
dt = new DataTable();
pName = new DataColumn("Product_Name", Type.GetType("System.String"));
pQty = new DataColumn("Quantity", Type.GetType("System.Int32"));
pPrice = new DataColumn("Price", Type.GetType("System.Int32"));
dt.Columns.Add(pName);
dt.Columns.Add(pQty);
dt.Columns.Add(pPrice);
dr = dt.NewRow();
dr["Product_Name"] = "Product 1";
dr["Quantity"] = 2;
dr["Price"] = 200;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Product_Name"] = "Product 2";
dr["Quantity"] = 5;
dr["Price"] = 480;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Product_Name"] = "Product 3";
dr["Quantity"] = 8;
dr["Price"] = 100;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Product_Name"] = "Product 4";
dr["Quantity"] = 2;
dr["Price"] = 500;
dt.Rows.Add(dr);
ds.Tables.Add(dt);
lvCustomers.DataSource = ds.Tables[0];
lvCustomers.DataBind();
}
protected void OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
(lvCustomers.FindControl("DataPager1") as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
this.BindListView();
}
protected void BindFormView()
{
DataSet ds = new DataSet();
DataTable dt;
DataRow dr;
DataColumn pName;
DataColumn pQty;
DataColumn pPrice;
int i = 0;
dt = new DataTable();
pName = new DataColumn("Product_Name", Type.GetType("System.String"));
pQty = new DataColumn("Quantity", Type.GetType("System.Int32"));
pPrice = new DataColumn("Price", Type.GetType("System.Int32"));
dt.Columns.Add(pName);
dt.Columns.Add(pQty);
dt.Columns.Add(pPrice);
dr = dt.NewRow();
dr["Product_Name"] = "Product 1";
dr["Quantity"] = 2;
dr["Price"] = 200;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Product_Name"] = "Product 2";
dr["Quantity"] = 5;
dr["Price"] = 480;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Product_Name"] = "Product 3";
dr["Quantity"] = 8;
dr["Price"] = 100;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Product_Name"] = "Product 4";
dr["Quantity"] = 2;
dr["Price"] = 500;
dt.Rows.Add(dr);
ds.Tables.Add(dt);
FormView1.DataSource = ds.Tables[0];
FormView1.DataBind();
}
protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
FormView1.PageIndex = e.NewPageIndex;
BindFormView();
}
protected void BindDetailsView() {
DataSet ds = new DataSet();
DataTable dt;
DataRow dr;
DataColumn pName;
DataColumn pQty;
DataColumn pPrice;
int i = 0;
dt = new DataTable();
pName = new DataColumn("Product_Name", Type.GetType("System.String"));
pQty = new DataColumn("Quantity", Type.GetType("System.Int32"));
pPrice = new DataColumn("Price", Type.GetType("System.Int32"));
dt.Columns.Add(pName);
dt.Columns.Add(pQty);
dt.Columns.Add(pPrice);
dr = dt.NewRow();
dr["Product_Name"] = "Product 1";
dr["Quantity"] = 2;
dr["Price"] = 200;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Product_Name"] = "Product 2";
dr["Quantity"] = 5;
dr["Price"] = 480;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Product_Name"] = "Product 3";
dr["Quantity"] = 8;
dr["Price"] = 100;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Product_Name"] = "Product 4";
dr["Quantity"] = 2;
dr["Price"] = 500;
dt.Rows.Add(dr);
ds.Tables.Add(dt);
DetailsView1.DataSource = ds.Tables[0];
DetailsView1.DataBind();
}
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
DetailsView1.PageIndex = e.NewPageIndex;
BindDetailsView();
}
}
If this helped you kindly accept the answer.Upendra Pratap ShahiPosted Jul 10, 2015, 4:39 AM
Upendra Pratap ShahiPosted Jul 10, 2015, 2:58 AM
anamika garewalPosted Jul 10, 2015, 2:29 AM
anamika garewalPosted Jul 10, 2015, 1:22 AM
Upendra Pratap ShahiPosted Jul 10, 2015, 1:14 AM