GridView模版列嵌套GirdView显示主从表数据

news/2025/2/23 15:27:04
<div id="article_content" class="article_content clearfix"> <div id="content_views" class="htmledit_views"> 当需要在一个列表中显示主从表(例如部门-人员的信息),在html" title=asp>asp.net1.1中我们可能会使用DataGrid模版列嵌套DataGrid的方法实现,然而,处理模版列里的DataGrid的翻页、排序、编辑等功能时都比较麻烦。在html" title=asp>asp.net2.0中,配合DataSource控件的使用让这个问题变得非常简单!
 
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <% @ Page Language="C#" AutoEventWireup="true" CodeFile="GridView_GirdView.html" title=asp>aspx.cs" Inherits="GridSamples_GridView_GirdView"  %>

<! 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 ="html" title=server>server" >
    
< title > 无标题页 </ title >
</ head >
< body >
    
< form  id ="form1"  runat ="html" title=server>server" >
    
< div >
        
< html" title=asp>asp:GridView  ID ="GridView1"  runat ="html" title=server>server"  AutoGenerateColumns ="False"  DataKeyNames ="deptid"
            DataSourceID
="AccessDataSource1"  AllowPaging ="True"  AllowSorting ="True"  PageSize ="2"  OnRowDataBound ="GridView1_RowDataBound" >
            
< Columns >
                
< html" title=asp>asp:BoundField  DataField ="deptid"  HeaderText ="部门编号"  InsertVisible ="False"  ReadOnly ="True"
                    SortExpression
="deptid"   />
                
< html" title=asp>asp:BoundField  DataField ="deptname"  HeaderText ="部门名称"  SortExpression ="deptname"   />
                
< html" title=asp>asp:BoundField  DataField ="deptremark"  HeaderText ="备注"  SortExpression ="deptremark"   />
                
< html" title=asp>asp:TemplateField  HeaderText ="人员信息" >
                    
< ItemTemplate >
                        
< html" title=asp>asp:GridView  ID ="GridView2"  runat ="html" title=server>server"  AutoGenerateColumns ="False"  DataKeyNames ="id"
                            DataSourceID
="AccessDataSource2"  AllowPaging ="True"  AllowSorting ="True"  PageSize ="5" >
                            
< Columns >
                                
< html" title=asp>asp:BoundField  DataField ="id"  HeaderText ="人员编号"  InsertVisible ="False"  ReadOnly ="True"
                                    SortExpression
="id"   />
                                
< html" title=asp>asp:BoundField  DataField ="name"  HeaderText ="姓名"  SortExpression ="name"   />
                                
< html" title=asp>asp:BoundField  DataField ="sex"  HeaderText ="性别"  SortExpression ="sex"   />
                            
</ Columns >
                            
< PagerSettings  FirstPageText ="首页"  LastPageText ="末页"  Mode ="NextPreviousFirstLast"
                NextPageText
="下一页"  PreviousPageText ="上一页"   />
                        
</ html" title=asp>asp:GridView >
                        
< html" title=asp>asp:AccessDataSource  ID ="AccessDataSource2"  runat ="html" title=server>server"  DataFile ="~/App_Data/test.mdb"
                            SelectCommand
="SELECT [id], [name], [sex], [deptid] FROM [employees] WHERE ([deptid] = ?)" >
                            
< SelectParameters >
                                
< html" title=asp>asp:Parameter  Name ="deptid"  Type ="Int32"   />
                            
</ SelectParameters >
                        
</ html" title=asp>asp:AccessDataSource >< br >
                    
</ ItemTemplate >
                
</ html" title=asp>asp:TemplateField >
                
            
</ Columns >
            
< PagerSettings  FirstPageText ="首页"  LastPageText ="末页"
                NextPageText
="下一页"  PreviousPageText ="上一页"   />
        
</ html" title=asp>asp:GridView >
        
< html" title=asp>asp:AccessDataSource  ID ="AccessDataSource1"  runat ="html" title=server>server"  DataFile ="~/App_Data/test.mdb"
            SelectCommand
="SELECT [deptid], [deptname], [deptremark], [createdate] FROM [departments]" >
        
</ html" title=asp>asp:AccessDataSource >
    
    
</ div >
    
</ form >
</ body >
</ html >
div> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">  1 using  System;
 2 using  System.Data;
 3 using  System.Configuration;
 4 using  System.Collections;
 5 using  System.Web;
 6 using  System.Web.Security;
 7 using  System.Web.UI;
 8 using  System.Web.UI.WebControls;
 9 using  System.Web.UI.WebControls.WebParts;
10 using  System.Web.UI.HtmlControls;
11
12 public  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}
div>
只需要上面几行简单的代码便可以实现。  div> div> <div id="treeSkill">div>

http://www.niftyadmin.cn/n/1415822.html

相关文章

JavaScript内置对象String对象,字符串案例

1 <!DOCTYPE html>2 <html lang"en">3 <head>4 <meta charset"UTF-8">5 <title></title>6 <script>7 //案例1:8 var str "我爱最帅的杨哥,太帅了";9 //console…

linux进入shell编程返回终端,linux中如何在得到当前终端窗口的宽度 - shell编程

获取终端大小时候的学习学习日期&#xff1a;2018/11/3问题来源&#xff1a;在写shell脚本时想输出一行占满整个终端屏幕宽度的 横杠发现for循环会导致执行缓慢解决方法&#xff1a;使用yes 命令sed 50q 显示50行tr -d \n 删除 \n多次重复输入相同字符可用yesyes "2"…

OpenStack icehouse系列之问题处理

OpenStack icehouse系列之问题处理众所周知搭建是很容易的、往往排错是很头疼的、下面我分享下我在搭建的过程中遇到的问题和解决办法。glance报错以及解决方法执行glance同步数据库的时候&#xff1a;su -s /bin/sh -c "glance-manage db_sync" glancesu -s /bin/sh…

linux 进程控制与通信,Linux进程控制与进程间通信.ppt

Linux进程控制与进程间通信* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 消息队列 第7章 第*页 消息队列的创建 系统调用msgget #include #include #include int msg…

构建配置 defaultConfig signingConfigs buildTypes productFlavors dependencies

测试项目位置&#xff1a;https://github.com/baiqiantao/FragmentTest.git 项目结构&#xff1a;project 目录的 build.gradle 文件// Top-level build file where you can add configuration options common to all sub-projects/modules. apply from: "config/config_d…

java抓取动态生成的网页--吐槽

2019独角兽企业重金招聘Python工程师标准>>> 最近在做项目的时候有一个需求&#xff1a;从网页面抓取数据&#xff0c;要求是首先抓取整个网页的html源码&#xff08;后期更新要使用到&#xff09;。刚开始一看这个简单&#xff0c;然后就稀里哗啦的敲起了代码&…

ArcGIS Server连接数据库密码修改后批量替换修复数据源

开发环境 ArcGIS Server 10.6 For Linux&#xff08;10.3适用&#xff09;、ArcGIS Desktop 10.3、Python 2.7.5 实现效果 连接数据库的密码修改后&#xff0c;原先旧密码的mxd文档无须手动修复数据源&#xff0c;仅需指定新旧数据源文件及mxd目录即可修复&#xff0c;修复后…

esp8266 linux开发环境搭建,ESP8266 Linux开发环境搭建

一、前言&#xff1a;Esp8266的windows开发环境编译程序比较慢&#xff0c;Linux编译相对windows快很多&#xff0c;所以选择在Ubuntu16.4 x64下搭建其开发环境。二、下载交叉编译器1.下载xtensa-lx106-elf.bz2在命令行状态下输入&#xff1a;git clone -b lx106 git://github.…