午夜视频在线网站,日韩视频精品在线,中文字幕精品一区二区三区在线,在线播放精品,1024你懂我懂的旧版人,欧美日韩一级黄色片,一区二区三区在线观看视频

分享

GridView模版列嵌套GirdView顯示主從表數(shù)據(jù) - №.零零伍 - 博客園

 素行 2007-03-17
當(dāng)需要在一個(gè)列表中顯示主從表(例如部門-人員的信息),在asp.net1.1中我們可能會(huì)使用DataGrid模版列嵌套DataGrid的方法實(shí)現(xiàn),然而,處理模版列里的DataGrid的翻頁、排序、編輯等功能時(shí)都比較麻煩。在asp.net2.0中,配合DataSource控件的使用讓這個(gè)問題變得非常簡單!
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridView_GirdView.aspx.cs" Inherits="GridSamples_GridView_GirdView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www./1999/xhtml" >
<head runat="server">
    
<title>無標(biāo)題頁</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="deptid"
            DataSourceID
="AccessDataSource1" AllowPaging="True" AllowSorting="True" PageSize="2" OnRowDataBound="GridView1_RowDataBound">
            
<Columns>
                
<asp:BoundField DataField="deptid" HeaderText="部門編號" InsertVisible="False" ReadOnly="True"
                    SortExpression
="deptid" />
                
<asp:BoundField DataField="deptname" HeaderText="部門名稱" SortExpression="deptname" />
                
<asp:BoundField DataField="deptremark" HeaderText="備注" SortExpression="deptremark" />
                
<asp:TemplateField HeaderText="人員信息">
                    
<ItemTemplate>
                        
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
                            DataSourceID
="AccessDataSource2" AllowPaging="True" AllowSorting="True" PageSize="5">
                            
<Columns>
                                
<asp:BoundField DataField="id" HeaderText="人員編號" InsertVisible="False" ReadOnly="True"
                                    SortExpression
="id" />
                                
<asp:BoundField DataField="name" HeaderText="姓名" SortExpression="name" />
                                
<asp:BoundField DataField="sex" HeaderText="性別" SortExpression="sex" />
                            
</Columns>
                            
<PagerSettings FirstPageText="首頁" LastPageText="末頁" Mode="NextPreviousFirstLast"
                NextPageText
="下一頁" PreviousPageText="上一頁" />
                        
</asp:GridView>
                        
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/test.mdb"
                            SelectCommand
="SELECT [id], [name], [sex], [deptid] FROM [employees] WHERE ([deptid] = ?)">
                            
<SelectParameters>
                                
<asp:Parameter Name="deptid" Type="Int32" />
                            
</SelectParameters>
                        
</asp:AccessDataSource><br>
                    
</ItemTemplate>
                
</asp:TemplateField>
                
            
</Columns>
            
<PagerSettings FirstPageText="首頁" LastPageText="末頁"
                NextPageText
="下一頁" PreviousPageText="上一頁" />
        
</asp:GridView>
        
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/test.mdb"
            SelectCommand
="SELECT [deptid], [deptname], [deptremark], [createdate] FROM [departments]">
        
</asp:AccessDataSource>
    
    
</div>
    
</form>
</body>
</html>
 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Collections;
 5using System.Web;
 6using System.Web.Security;
 7using System.Web.UI;
 8using System.Web.UI.WebControls;
 9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class GridSamples_GridView_GirdView : System.Web.UI.Page
13{
14    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
15    {
16        if (e.Row.RowIndex > -1)
17        {
18            AccessDataSource accessDS = e.Row.FindControl("AccessDataSource2"as AccessDataSource;
19            accessDS.SelectParameters["deptid"].DefaultValue = e.Row.Cells[0].Text;
20        }

21    }

22}

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多