Step 1:- Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Demo.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Product
Wise Data</title>
<style type="text/css">
.cssgd, .cssgd1 {
border-collapse: collapse;
border: solid 1px #CCCCCC;
}
.cssgd th, .cshd, .cshd * {
background: #990000;
color: White;
}
.cssitem, .cssitem * {
background: #FFFBD6;
color: #333333;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div visible="true" id="dv1" runat="server">
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:Panel runat="server" ID="pnl1" Style="float: left; padding-top: 15px;">
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
<tr>
<td>
<table cellpadding="4" cellspacing="0" align="left">
<tr>
<td style="color: Maroon; font-weight: bold;">Order No :
</td>
<td style="color: Black; font-weight: bold;">
<%# DataBinder.Eval(Container.DataItem, "OrderNo") %>
</td>
<td style="color: Maroon; font-weight: bold;"> Shop
Keeper Name :
</td>
<td style="color: Black; font-weight: bold;">
<%# DataBinder.Eval(Container.DataItem, "ShopKeeperName")%>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<hr style="width: 100%; display: block;" />
</td>
</tr>
<tr>
<td>
<asp:Repeater ID="RepReport" runat="server" DataSource='<%# GetDt(Convert.ToString(Eval("OrderNo"))) %>'>
<HeaderTemplate>
<table border="0" class="cssgd" cellpadding="4" cellspacing="0">
<thead>
<tr>
<th style="width: 30px">S.No
</th>
<th style="width: 30px">Order_Date
</th>
<th style="width: 30px">Shop_Keeper_Name
</th>
<th style="width: 30px">Product_Name
</th>
<th style="width: 30px">Product_Quantity
</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr class="cssitem">
<td>
<%#(((RepeaterItem)Container).ItemIndex+1).ToString() %>
</td>
<td align="left" valign="middle">
<%# Eval("Date", "{0:dd-MM-yyyy}")%>
</td>
<td align="left" valign="middle">
<%# Eval("ShopKeeperName")%>
</td>
<td align="left" valign="middle">
<%# Eval("ProductName")%>
</td>
<td align="left" valign="middle">
<%# Eval("ProductQuantity")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
<tfoot>
<tr class="cshd" style="background: #990000; color: White;">
<td>Total
</td>
<td></td>
<td></td>
<td></td>
<td align="center">
<%#SumCalc("ProductQuantity", Convert.ToString(DataBinder.Eval(Container.DataItem, "OrderNo")))%>
</td>
</tr>
</tfoot>
</table>
</td> </tr> </table>
</asp:Panel>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
Step
2:- Default.aspx.cs
using System;
using System.Data;
using System.Web.UI;
namespace Demo
{
public partial class Default : Page
{
private DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dt
= new DataTable();
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("OrderNo", typeof(string));
dt.Columns.Add("ShopKeeperName", typeof(string));
dt.Columns.Add("ProductName", typeof(string));
dt.Columns.Add("ProductQuantity", typeof(int));
DataRow dr
= null;
dr
= dt.NewRow();
dr["Date"] = "2013-12-01";
dr["OrderNo"] = "A11";
dr["ShopKeeperName"] = "RAM";
dr["ProductName"] = "PRODUCT
1";
dr["ProductQuantity"] = "10";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-01";
dr["OrderNo"] = "A11";
dr["ShopKeeperName"] = "RAM";
dr["ProductName"] = "PRODUCT
2";
dr["ProductQuantity"] = "10";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-01";
dr["OrderNo"] = "A11";
dr["ShopKeeperName"] = "RAM";
dr["ProductName"] = "PRODUCT
3";
dr["ProductQuantity"] = "10";
dt.Rows.Add(dr);
//-------------------------------------
dr
= dt.NewRow();
dr["Date"] = "2013-12-01";
dr["OrderNo"] = "A12";
dr["ShopKeeperName"] = "SHAYAM";
dr["ProductName"] = "PRODUCT
1";
dr["ProductQuantity"] = "20";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-01";
dr["OrderNo"] = "A12";
dr["ShopKeeperName"] = "SHAYAM";
dr["ProductName"] = "PRODUCT
2";
dr["ProductQuantity"] = "20";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-01";
dr["OrderNo"] = "A12";
dr["ShopKeeperName"] = "SHAYAM";
dr["ProductName"] = "PRODUCT
3";
dr["ProductQuantity"] = "20";
dt.Rows.Add(dr);
//-------------------------------------
//-------------------------------------
dr
= dt.NewRow();
dr["Date"] = "2013-12-02";
dr["OrderNo"] = "A11";
dr["ShopKeeperName"] = "RAM";
dr["ProductName"] = "PRODUCT
1";
dr["ProductQuantity"] = "10";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-02";
dr["OrderNo"] = "A11";
dr["ShopKeeperName"] = "RAM";
dr["ProductName"] = "PRODUCT
2";
dr["ProductQuantity"] = "10";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-02";
dr["OrderNo"] = "A11";
dr["ShopKeeperName"] = "RAM";
dr["ProductName"] = "PRODUCT
3";
dr["ProductQuantity"] = "10";
dt.Rows.Add(dr);
//-------------------------------------
dr
= dt.NewRow();
dr["Date"] = "2013-12-02";
dr["OrderNo"] = "A12";
dr["ShopKeeperName"] = "SHAYAM";
dr["ProductName"] = "PRODUCT
1";
dr["ProductQuantity"] = "20";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-02";
dr["OrderNo"] = "A12";
dr["ShopKeeperName"] = "SHAYAM";
dr["ProductName"] = "PRODUCT
2";
dr["ProductQuantity"] = "20";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-02";
dr["OrderNo"] = "A12";
dr["ShopKeeperName"] = "SHAYAM";
dr["ProductName"] = "PRODUCT
3";
dr["ProductQuantity"] = "20";
dt.Rows.Add(dr);
//-------------------------------------
//-------------------------------------
dr
= dt.NewRow();
dr["Date"] = "2013-12-01";
dr["OrderNo"] = "A13";
dr["ShopKeeperName"] = "KUMAR";
dr["ProductName"] = "PRODUCT
4";
dr["ProductQuantity"] = "10";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-01";
dr["OrderNo"] = "A13";
dr["ShopKeeperName"] = "KUMAR";
dr["ProductName"] = "PRODUCT
5";
dr["ProductQuantity"] = "10";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-01";
dr["OrderNo"] = "A13";
dr["ShopKeeperName"] = "KUMAR";
dr["ProductName"] = "PRODUCT
6";
dr["ProductQuantity"] = "10";
dt.Rows.Add(dr);
//-------------------------------------
//-------------------------------------
dr
= dt.NewRow();
dr["Date"] = "2013-12-02";
dr["OrderNo"] = "A14";
dr["ShopKeeperName"] = "KARAN";
dr["ProductName"] = "PRODUCT
7";
dr["ProductQuantity"] = "20";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-02";
dr["OrderNo"] = "A14";
dr["ShopKeeperName"] = "KARAN";
dr["ProductName"] = "PRODUCT
8";
dr["ProductQuantity"] = "20";
dt.Rows.Add(dr);
dr
= dt.NewRow();
dr["Date"] = "2013-12-02";
dr["OrderNo"] = "A14";
dr["ShopKeeperName"] = "KARAN";
dr["ProductName"] = "PRODUCT
9";
dr["ProductQuantity"] = "20";
dt.Rows.Add(dr);
DataList1.DataSource
= dt.DefaultView.ToTable(true, new string[]
{ "OrderNo", "ShopKeeperName" });
DataList1.DataBind();
}
}
public DataTable GetDt(string OrderNo)
{
string fil
= " OrderNo='" + OrderNo.Trim()
+ "'";
DataView dv =
dt.DefaultView;
dv.RowFilter
= fil;
return dv.Table;
}
public string SumCalc(string col, string OrderNo)
{
string fil
= " OrderNo='" + OrderNo + "'";
string strsum
= dt.Compute("Sum(" + col + ")",
fil).ToString();
return strsum;
}
}
}
Step 3:- Output
Explanation:-
Result Set
DataList1.DataSource = dt.DefaultView.ToTable(true, new string[] { "OrderNo", "ShopKeeperName" });
DataList1.DataBind();
This line returns the filter data from the result set based on
Order No and ShopKeeperName.
So you will get the below result set.
In
DataList control, I am using the Repeater Control to repeat the same template
block.
<asp:Repeater ID="RepReport" runat="server" DataSource='<%# GetDt(Convert.ToString(Eval("OrderNo"))) %>'>
When
we bind the DataList control with the filter result set, So each row record
data call the GetDt () function i.e. In code behind file and get the all record
from the result set based on order no.
Same
I am using to display sum in the footer.
<%#SumCalc("ProductQuantity", Convert.ToString(DataBinder.Eval(Container.DataItem, "OrderNo")))%>
No comments:
Post a Comment