ASPxGridView是一个方便的数据显示控件,可是自动的绑定我们所需要的数据,但是有时,当数据属性过多时,我们并不一定要把所有的信息提供给所有的人,当有人需要这些数据时可以自动的进行查看,这时就可以把一些主要的信息提供给所有人,对于一些细节信息,可以按照个人的需求就行显示,这就要用到ASPxGridView的DetailRow了,本文将以铁路列车信息数据库为依据,首先显所有的列车车次,点击后查看列车详情,效果图如下:

本文实现的效果和前面介绍的ASPxPop控件的效果类似,但是这个控件也可以用在不方便使用那和空间的时候,读者可以对比博文http://blog.sina.com.cn/s/blog_62cd5a980100v6xx.html,进行选择,上代码:

前端代码:

<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.2, Version=9.2.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"

Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>

<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.2, Version=9.2.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"

Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>

<!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>具有详细信息的AspGridView测试</title>

</head>

<body>

<form id="form1" runat="server">

<div align="center">

<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" CssFilePath="~/App_Themes/Office2003Blue/{0}/styles.css"

CssPostfix="Office2003_Blue" Caption="全国火车车次信息表" KeyFieldName="ID" ClientInstanceName="grid">

<Styles CssFilePath="~/App_Themes/Office2003Blue/{0}/styles.css" CssPostfix="Office2003_Blue">

<Header ImageSpacing="5px" SortingImageSpacing="5px">

</Header>

<LoadingPanel ImageSpacing="10px">

</LoadingPanel>

</Styles>

<Images ImageFolder="~/App_Themes/Office2003Blue/{0}/">

<CollapsedButton Height="12px" Url="~/App_Themes/Office2003Blue/GridView/gvCollapsedButton.png"

Width="11px" />

<ExpandedButton Height="12px" Url="~/App_Themes/Office2003Blue/GridView/gvExpandedButton.png"

Width="11px" />

<DetailCollapsedButton Height="12px" Url="~/App_Themes/Office2003Blue/GridView/gvCollapsedButton.png"

Width="11px" />

<DetailExpandedButton Height="12px" Url="~/App_Themes/Office2003Blue/GridView/gvExpandedButton.png"

Width="11px" />

<FilterRowButton Height="13px" Width="13px" />

</Images>

<StylesEditors>

<ProgressBar Height="25px">

</ProgressBar>

</StylesEditors>

<SettingsPager PageSize="15">

</SettingsPager>

            <SettingsDetail ShowDetailRow="true" AllowOnlyOneMasterRowExpanded="True" ExportMode="All" />

<ClientSideEvents RowClick="function(s, e) {

_aspxClearSelection();

grid._selectAllRowsOnPage(false);

grid.SelectRow(e.visibleIndex, true);

}" />

<Columns>

<dxwgv:GridViewDataColumn Caption="序号">

<DataItemTemplate>

<%#Container.ItemIndex+1 %>

</DataItemTemplate>

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="车次" FieldName="ID" Width="200PX">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="列车类型" FieldName="type" Width="200PX">

</dxwgv:GridViewDataColumn>

</Columns>

<Templates>

<DetailRow>

<dxwgv:ASPxGridView ID="ASPxGridView2" runat="server" CssFilePath="~/App_Themes/Office2003Blue/{0}/styles.css"

CssPostfix="Office2003_Blue" OnDataBinding="getnewdata">

<Styles CssFilePath="~/App_Themes/Office2003Blue/{0}/styles.css" CssPostfix="Office2003_Blue">

<Header ImageSpacing="5px" SortingImageSpacing="5px">

</Header>

<LoadingPanel ImageSpacing="10px">

</LoadingPanel>

</Styles>

<SettingsPager PageSize="10">

</SettingsPager>

                        <SettingsDetail IsDetailGrid="true" />

<Images ImageFolder="~/App_Themes/Office2003Blue/{0}/">

<CollapsedButton Height="12px" Url="~/App_Themes/Office2003Blue/GridView/gvCollapsedButton.png"

Width="11px" />

<ExpandedButton Height="12px" Url="~/App_Themes/Office2003Blue/GridView/gvExpandedButton.png"

Width="11px" />

<DetailCollapsedButton Height="12px" Url="~/App_Themes/Office2003Blue/GridView/gvCollapsedButton.png"

Width="11px" />

<DetailExpandedButton Height="12px" Url="~/App_Themes/Office2003Blue/GridView/gvExpandedButton.png"

Width="11px" />

<FilterRowButton Height="13px" Width="13px" />

</Images>

<StylesEditors>

<ProgressBar Height="25px">

</ProgressBar>

</StylesEditors>

<Columns>

<dxwgv:GridViewDataColumn Caption="序号">

<DataItemTemplate>

<%#Container.ItemIndex+1 %>

</DataItemTemplate>

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="车次" FieldName="ID">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="到站" FieldName="Station">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="到站时间" FieldName="A_Time">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="发车时间" FieldName="D_Time">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="天数" FieldName="Day">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="里程" FieldName="Distance">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="一等座" FieldName="P1">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="二等座" FieldName="P2">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="三等座" FieldName="P3">

</dxwgv:GridViewDataColumn>

<dxwgv:GridViewDataColumn Caption="四等座" FieldName="P4">

</dxwgv:GridViewDataColumn>

</Columns>

</dxwgv:ASPxGridView>

</DetailRow>

</Templates>

</dxwgv:ASPxGridView>

</div>

</form>

</body>

</html>

后端代码:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
using DevExpress.Web.ASPxGridView;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AspxGridViewDataBind();
        }
        else
        {
            if (ViewState["ASPxGridView1"] !=null)
            {
                DataSet ds = ViewState["ASPxGridView1"] as DataSet;
                this.ASPxGridView1.DataSource = ds;
                this.ASPxGridView1.DataBind();
            }
        }
 
    }
    public OleDbConnection getConnection() 
    {
        OleDbConnection conn = null;
        string connectionstr = "provider=Microsoft.JET.OLEDB.4.0;";
        connectionstr += @"data source=d:\database\train.mdb";
        try
        {
            conn = new OleDbConnection(connectionstr);
            conn.Open();
            //ScriptManager.RegisterStartupScript(this,this.GetType(),"","alert('建立连接成功!');",true);
        }
        catch (Exception e)
        {
            
            Response.Write("建立数据库连接失败!"+e.Message);
        }
        return conn;
    }
    public void closeConnection(OleDbConnection conn) 
    {
        try
        {
            conn.Close();
        }
        catch (Exception e)
        {
            
            Response.Write("关闭数据连接失败!"+e.Message);
        }
    }
    public DataSet getDataSet(OleDbConnection conn) 
    {
        DataSet ds = new DataSet();
        string sql = "select distinct ID,type from train ";
        //string sql="select * from train";
        try
        {
            OleDbDataAdapter oda = new OleDbDataAdapter(sql,conn);
            oda.Fill(ds);
        }
        catch (Exception e)
        {
 
            Response.Write("获取结果集失败!"+e.Message) ;
        }
        return ds;
    }
    public void display() 
    {
        OleDbConnection conn = getConnection();
        DataSet ds = getDataSet(conn);
        for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
        {
            Response.Write(ds.Tables[0].Columns[i].ColumnName.ToString()+"<br/>");
        }
        closeConnection(conn);
    }
    public void AspxGridViewDataBind()
    {
        OleDbConnection conn = getConnection();
        DataSet ds = getDataSet(conn);
        this.ASPxGridView1.DataSource = ds;
        this.ASPxGridView1.DataBind();
        ViewState["ASPxGridView1"] = ds;
        closeConnection(conn);
    }
    public void getnewdata(object sender,EventArgs e) 
    {
        ASPxGridView grid = (ASPxGridView)sender;
        string id = grid.GetMasterRowFieldValues("ID").ToString();
        //this.Response.Write(id);
        DataSet ds = getDetailData(id);
        grid.DataSource = ds;
        //ViewState["grid"] = ds;
    }
    public DataSet getDetailData(string id) 
    {
        DataSet ds = new DataSet();
        string sql = "select * from train where id='"+id+"'";
        OleDbConnection conn = getConnection();
        OleDbDataAdapter oda = new OleDbDataAdapter(sql,conn);
        oda.Fill(ds);
        closeConnection(conn);
        return ds;
    }
}
 
源地址:http://blog.sina.com.cn/s/blog_62cd5a980100vmge.html

ASPxGridView中DetailRow的使用的更多相关文章

  1. ASPxGridView中如何对主从表绑定数据

    注:在从表的aspxgridview中的(OnDataBinding()事件中绑定数据)-----代码如下 //绑定属性值表protected void grid2_sonTable_DataBind ...

  2. dev中如何对combox下拉框设置可消除属性以及ASPxGridView中金额,数量的显示,以及总计、grid中某行值

    下拉框属性关键:IncrementalFilteringMode="StartsWith" DropDownStyle="DropDown" ASPxGridV ...

  3. 如何使用编辑模板在ASPxGridView中进行新增修改(除去常规的gridviw模板编辑外)

    aspgridview模板编辑效果图: //前端代码:(核心: <Templates><EditForm>.....中间可用栅格样式布局等(随意)...</Templat ...

  4. 获取ASPxGridView 中的数据(仅仅是获取;注意模板是如何获取的)

    1.取得控件值 using System.Collections.Generic; //取得当前控件值的集合 直接寻找控件的ID List<object> keyValues = this ...

  5. ASPxGridView中批量提交及个别提交的写法

    //获取chech box ID protected string GetProtoID() { string protoId = ""; //获取选中的记录Id List< ...

  6. ASPxGridView中Command列自定义按钮点击事件概要

    其中CustomButtonClick="ButtonClick",e.buttonID可以获取到自定义按钮的id e.visibleIndex获取到行的索引 grdList.Ge ...

  7. devexpress中ASPxGridView控件初始化赋值

    写在ASPxGridView中OnCellEditorInitialize="ASPxGridView_progoods_CellEditorInitialize"  事件中: / ...

  8. asp.net(c#)中如何在前端用js写条件查询,且不用调用存储过程

    前端页面(源): <dx:ASPxButton ID="ASPxButton_Select" runat="server" Text="查询&q ...

  9. DevExpress之ASPxGridView笔记(1)

    1.设置Row(某列)输出格式,例如,在数字前加美元符.每3位以逗号隔开及设置小数点后两位: <dx:GridViewDataTextColumn FieldName="SHOUHUI ...

随机推荐

  1. 开源App之MyHearts(二)

    前言 小弟技术有限,有的地方也是自己摸索出来的,可能和大神们写的好的代码没法比,但是我会努力的.要对自己说下,加油!! 此次更新 1.集成QQ登录完成 集成QQ登录网上写的介绍已经很多了,这里就不详细 ...

  2. IIS_PUT

    [*] Put file success http://58.16.95.114:80/1470546504.01.txt [*] Put file success http://58.17.121. ...

  3. 009. C#中的WebBrowser控件的属性、方法及操作演示代码(转)

    本文转自 http://www.open-open.com/code/view/1430559996802 0.常用方法 Navigate(string urlString):浏览urlString表 ...

  4. 【Swift】读取文本文件字符串

    var str:NSString = NSString.stringWithContentsOfFile(_srcouceFilePath,encoding:NSUTF8StringEncoding, ...

  5. gcc、g++

    http://hi.baidu.com/zhangcunli8499/item/257e187360b48b2bd6a89cc6 g++ src/*.cpp -I include/ -I includ ...

  6. R(一): R基础知识

    R 是一门拥有统计分析及作图功能的免费软件,主要用于数学建模.统计计算.数据处理.可视化等方向.据 IEEE Spectrum发布的2016年编程语言前10位排名来看,R语言由2015年排名第6位上升 ...

  7. 每日学习心得:SQL查询表的行列转换/小计/统计(with rollup,with cube,pivot解析)

    2013-8-20 1.    SQL查询表的行列转换/小计/统计(with  rollup,with cube,pivot解析) 在实际的项目开发中有很多项目都会有报表模块,今天就通过一个小的SQL ...

  8. .NET使用OpenSSL生成的pem密钥文件

    NET要使用OpenSSL生成的pem密钥文件,网上资料很少(http://www.faqs.org/rfcs/rfc1421.html,RFC1421文件又老长老长),仅有的资料还是有错误的,所以今 ...

  9. framework 安装出错 1603

    安装frame work 3.5的时候老是出现 1603错误. 百度了一圈,各种方法都试了,仍不行. 像: 1.打开临时目录看安装日志,然后修改注册表Main的权限. 2.停止服务Cryptograp ...

  10. linux系统中实现mongodb3.0.5数据库自动备份

    最近两天,因公司业务需要,要定期备份mongodb数据库中的数据. 查了很多资料后,发现mongodb似乎并没有自带的定时备份功能,于是只好转移目标到linux系统的定时任务上,于是学习并使用了cro ...