CodeSmith NetTier 对于主从表级联显示的SAMPLE ObjectDataSource

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

public partial class PurchaseModule_PurchaseRequestCreate : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{

    }

    
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    
{
       

    }

    
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
if (e.Row.RowIndex > -1)
        
{
            SqlDataSource objDS 
= e.Row.FindControl("SqlDataSource1"as SqlDataSource;
            objDS.SelectParameters[
"Param1"].DefaultValue = e.Row.Cells[0].Text;
        }

    }

}

前台页面案例
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PurchaseRequestCreate.aspx.cs" Inherits="PurchaseModule_PurchaseRequestCreate" %>

<!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">
        
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#CCCCCC"
            BorderColor
="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
            DataKeyNames
="RequestID" DataSourceID="PurchaseRequestDataSource1" ForeColor="Black"
            OnRowDataBound
="GridView1_RowDataBound">
            
<FooterStyle BackColor="#CCCCCC" />
            
<Columns>
                
<asp:BoundField DataField="RequestID" HeaderText="流水号" InsertVisible="False"
                    ReadOnly
="True" SortExpression="RequestID" />
                
<asp:BoundField DataField="RequestCode" HeaderText="申请号码" SortExpression="RequestCode" />
                
<asp:BoundField DataField="ReleaseCode" HeaderText="审核状态" SortExpression="ReleaseCode" />
                
<asp:BoundField DataField="Requestor" HeaderText="申请人" SortExpression="Requestor" />
                
<asp:BoundField DataField="RequestDepartmentID" HeaderText="申请部门"
                    SortExpression
="RequestDepartmentID" />
                
<asp:BoundField DataField="RequestDate" HeaderText="申请日期" SortExpression="RequestDate" />
                
<asp:BoundField DataField="Desc1" HeaderText="备注" SortExpression="Desc1" />
                
<asp:TemplateField HeaderText="采购明细">
                    
<ItemTemplate>
                        
&nbsp;
                        
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BLUEBEANSConnectionString %>"
                            SelectCommand
="SELECT * FROM PurchaseRequestItem WHERE (RequestID = @Param1)">
                            
<SelectParameters>
                                
<asp:Parameter Name="Param1" />
                            
</SelectParameters>
                        
</asp:SqlDataSource>
                        
<asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False" BackColor="White"
                            BorderColor
="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
                            DataSourceID
="SqlDataSource1" GridLines="None" Height="50px" Width="125px">
                            
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                            
<EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                            
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                            
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                            
<Fields>
                                
<asp:BoundField DataField="RequestID" HeaderText="RequestID" SortExpression="RequestID" Visible="False" />
                                
<asp:BoundField DataField="ProductName" HeaderText="采购物品" SortExpression="ProductName" />
                                
<asp:BoundField DataField="ProductID" HeaderText="ProductID" SortExpression="ProductID" Visible="False" />
                                
<asp:BoundField DataField="Unit" HeaderText="单位" SortExpression="Unit" />
                                
<asp:BoundField DataField="Amount" HeaderText="采购量" SortExpression="Amount" />
                                
<asp:BoundField DataField="ReceivedAmount" HeaderText="接收量" SortExpression="ReceivedAmount" />
                                
<asp:BoundField DataField="VendorName" HeaderText="供应商" SortExpression="VendorName" />
                            
</Fields>
                            
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
                        
</asp:DetailsView>
                    
</ItemTemplate>
                
</asp:TemplateField>
                
<asp:CommandField ShowEditButton="True" />
                
<asp:CommandField ShowDeleteButton="True" />
            
</Columns>
            
<RowStyle BackColor="White" />
            
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
            
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
            
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        
</asp:GridView>
        
&nbsp; &nbsp;&nbsp;
        
<data:PurchaseRequestDataSource ID="PurchaseRequestDataSource" runat="server" SelectMethod="GetByRequestID">
            
<Parameters>
                
<asp:QueryStringParameter Name="RequestID" QueryStringField="RequestID" Type="String" />
            
</Parameters>
        
</data:PurchaseRequestDataSource>
        
<data:PurchaseRequestDataSource ID="PurchaseRequestDataSource1" runat="server" SelectMethod="GetAll">
        
</data:PurchaseRequestDataSource>
        
<data:DepartmentDataSource ID="DepartmentDataSource" runat="server" EnablePaging="True"
            EnableSorting
="True" SelectMethod="GetPaged">
            
<Parameters>
            
</Parameters>
        
</data:DepartmentDataSource>
        
<data:PurchaseRequestTypeDataSource ID="RequestTypeIDPurchaseRequestTypeDataSource"
            runat
="server" SelectMethod="GetAll">
        
</data:PurchaseRequestTypeDataSource>
        
<br />
        
<data:PurchaseRequestItemDataSource ID="PurchaseRequestItemDataSource" runat="server"
            EnablePaging
="True" EnableSorting="True" SelectMethod="GetPaged">
            
<Parameters>
                
<data:CustomParameter ConvertEmptyStringToNull="false" Name="WhereClause" Value="" />
                
<data:CustomParameter ConvertEmptyStringToNull="false" Name="OrderByClause" Value="" />
                
<asp:ControlParameter ControlID="GridView1" Name="PageIndex" PropertyName="PageIndex"
                    Type
="Int32" />
                
<asp:ControlParameter ControlID="GridView1" Name="PageSize" PropertyName="PageSize"
                    Type
="Int32" />
                
<data:CustomParameter Name="RecordCount" Type="Int32" Value="0" />
            
</Parameters>
        
</data:PurchaseRequestItemDataSource>
    
</form>
</body>
</html>
数据库设计


UI显示效果


原文地址:https://www.cnblogs.com/SlashOut/p/834895.html