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>