Bare som en art eksempel:
// data
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
/// <summary>
/// Summary description for DetailsMaster
/// </summary>
public class DetailsMaster
{
public List<Product> GetProducts()
{
List<Product> products = new List<Product>();
products.Add(new Product(1, "p1"));
products.Add(new Product(2, "p2"));
products.Add(new Product(3, "p3"));
products.Add(new Product(4, "p4"));
products.Add(new Product(5, "p5"));
products.Add(new Product(6, "p6"));
products.Add(new Product(7, "p7"));
products.Add(new Product(8, "p8"));
return products;
}
public List<Price> GetPrices(int productId)
{
List<Price> prices = new List<Price>();
prices.Add(new Price(1, 100));
prices.Add(new Price(1, 100));
prices.Add(new Price(2, 200));
prices.Add(new Price(2, 200));
prices.Add(new Price(1, 100));
prices.Add(new Price(1, 100));
prices.Add(new Price(5, 500));
prices.Add(new Price(5, 500));
return prices.FindAll(
delegate(Price price)
{
if(price.ProductId == productId)
return true;
return false;
});
}
}
public class Product
{
private int m_ProductId;
public int ProductId
{
get { return m_ProductId; }
set { m_ProductId = value; }
}
private string m_Name = "produktnavn";
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
public Product(int productId, string name)
{
m_ProductId = productId;
m_Name = name;
}
}
public class Price
{
private int m_Price;
public int PriceIncTax
{
get { return m_Price; }
set { m_Price = value; }
}
private int m_ProductId = 1;
public int ProductId
{
get { return m_ProductId; }
set { m_ProductId = value; }
}
public Price(int productId, int price)
{
m_ProductId = productId;
m_Price = price;
}
}
// og din aspx-side
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DetailsMaster.aspx.cs" Inherits="MasterDetail_DetailsMaster" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
DataSourceID="dsProducts" Height="50px" Width="125px" DataKeyNames="ProductId">
<Fields>
<asp:BoundField DataField="ProductId" HeaderText="ProductId" SortExpression="ProductId" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="dsProducts" runat="server" SelectMethod="GetProducts" TypeName="DetailsMaster">
</asp:ObjectDataSource>
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="dsPrices">
<Columns>
<asp:BoundField DataField="ProductId" HeaderText="ProductId" SortExpression="ProductId" />
<asp:BoundField DataField="PriceIncTax" HeaderText="PriceIncTax" SortExpression="PriceIncTax" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="dsPrices" runat="server" SelectMethod="GetPrices" TypeName="DetailsMaster">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1" Name="productId" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</form>
</body>
</html>
Det er bare genereret af designeren.
Mvh