彩票走势图

如何利用ASPxGridView里的主从报表创建列表页面

原创|其它|编辑:郝浩|2012-10-15 11:10:07.000|阅读 591 次

概述:本文介绍了如何利用ASPxGridView里的Master-Detail创建列表页面。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

ASPxGridView套件是一个功能完备的ASP.NET网格和编辑器库,而里面的Master-Detail能够使主表与子表的信息在同一页面展示,无须新建子表页面。

今天尝试使用ASPxGridView中的Master-Detail完成了一个列表页面,下面是我的制作步骤及其经验总结:

1、在aspx页面上拖放2个控件。aspxgridview和ObjectDataSource,分别命名为grid和objSaleUser

2、为 ObjectDataSource添加数据源。

3、设置 grid的数据源为objSaleUser,设置KeyFieldName和AutoGenerateColumns="False",添加你想显示的列。

 设置SettingsDetail下的 ShowDetailRow="True" 

如何利用ASPxGridView里的主从报表创建列表页面

4、 为grid编辑模板,选择DetailRow,光标定位于DetailRow,拖放一个aspxgridview进去,命名为detailGrid。

如何利用ASPxGridView里的主从报表创建列表页面

如何利用ASPxGridView里的主从报表创建列表页面

如何利用ASPxGridView里的主从报表创建列表页面

5、为detailGrid拖放一个ObjectDataSource到页面中,重命名为ObjSaleUserWeeklyReports

配置数据源和定义参数,因GetFinishedWeeklyReports中有一个实参saleUserID,所以在定义参数中为其设置一个 session。

如何利用ASPxGridView里的主从报表创建列表页面

6、设置detailGrid的数据源为ObjSaleUserWeeklyReports,设置KeyFieldName和 AutoGenerateColumns="False",添加你想显示的列,设置SettingsDetail下的IsDetailGrid="true"。

如何利用ASPxGridView里的主从报表创建列表页面

7、给detailGrid添加事件BeforePerformDataSelect,查看帮助文档知Occurs before the ASPxGridView control obtains data from a data source. When implementing a master-detail mode, the BeforePerformDataSelect event should be handled to specify session values.在后台文件cs中为Session["saleUserID"]赋值。Session["saleUserID"] = (sender as ASPxGridView).GetMasterRowKeyValue();

8、前后台代码如下:

Code highlighting produced by Actipro CodeHighlighter (freeware)
//www.CodeHighlighter.com/

--><%@ Page Language="C#" AutoEventWireup="true" CodeFile="SaleUserListReport.aspx.cs"
    Inherits="Report_SaleUserListReport" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="DevExpress.Web.v8.1, Version=8.1.3.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    Namespace="DevExpress.Web.ASPxPager" TagPrefix="dxpg" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Assembly="DevExpress.Web.v8.1, Version=8.1.3.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    Namespace="DevExpress.Web.ASPxTabControl" TagPrefix="dxtc" %>
<%@ Register Assembly="DevExpress.Web.v8.1, Version=8.1.3.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    Namespace="DevExpress.Web.ASPxClasses" TagPrefix="dxw" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.1, Version=8.1.3.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.1, Version=8.1.3.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<html xmlns="//www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">  
        <dxtc:ASPxPageControl ID="ASPxPageControl1" runat="server" ActiveTabIndex="0" AutoPostBack="True"
            Width="99%" Height="590px">
            <ActiveTabStyle BackColor="Transparent">
            </ActiveTabStyle>
            <ContentStyle BackColor="Transparent">
                <Border BorderColor="#002D96" BorderStyle="Solid" BorderWidth="1px"></Border>
            </ContentStyle>
            <Paddings Padding="0px"></Paddings>
            <LoadingPanelStyle ImageSpacing="6px" BackColor="Transparent">
            </LoadingPanelStyle>
            <TabPages>
                <dxtc:TabPage Text="销售人员周报">
                    <ContentCollection>
                        <dxw:contentcontrol runat="server">
                            <table>
                                <tr>
                                    <td style="width: 256px">
                                        <dxwgv:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="objSaleUser"
                                            KeyFieldName="U_ID" ClientInstanceName="grid" Width="800px">
                                            <SettingsText EmptyDataRow="没有数据"></SettingsText>
                                            <SettingsLoadingPanel Text="正在加载..."></SettingsLoadingPanel>
                                            <Styles>
                                                <Header ImageSpacing="5px" SortingImageSpacing="5px" HorizontalAlign="Center">
                                                </Header>
                                                <LoadingPanel ImageSpacing="10px">
                                                </LoadingPanel>
                                                <AlternatingRow Enabled="True" />
                                            </Styles>
                                            <Columns>
                                                <dxwgv:GridViewDataTextColumn FieldName="PI_NAME" VisibleIndex="0" Caption="姓名">
                                                    <CellStyle HorizontalAlign="Center">
                                                    </CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                <dxwgv:GridViewDataTextColumn FieldName="PI_CODE" VisibleIndex="1" Caption="编码">
                                                    <CellStyle HorizontalAlign="Center">
                                                    </CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                <dxwgv:GridViewDataTextColumn FieldName="PI_TELNUM" VisibleIndex="2" Caption="公司电话">
                                                    <CellStyle HorizontalAlign="Center">
                                                    </CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                <dxwgv:GridViewDataTextColumn FieldName="PI_EMAIL" VisibleIndex="3" Caption="公司邮箱"
                                                    Width="150px">
                                                    <CellStyle HorizontalAlign="Center">
                                                    </CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                <dxwgv:GridViewDataTextColumn FieldName="PI_MOBILEPHONE" VisibleIndex="4" Caption="个人电话">
                                                    <CellStyle HorizontalAlign="Center">
                                                    </CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                <dxwgv:GridViewDataTextColumn FieldName="PI_GTALK" VisibleIndex="5" Caption="GTalk"
                                                    Width="150px">
                                                    <CellStyle HorizontalAlign="Center">
                                                    </CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                            </Columns>
                                            <SettingsDetail AllowOnlyOneMasterRowExpanded="True" ShowDetailRow="True" />
                                            <Templates>
                                                <DetailRow>
                                                     销售经理: <b>
                                                        <%# Eval("U_NAME")%>
                                                    </b>, 最近一个月的周报
                                                    <br />
                                                    <br />
                                                    <dxwgv:ASPxGridView ID="detailGrid" runat="server" Width="750px" AutoGenerateColumns="False"
                                                        ClientInstanceName="detailGrid" KeyFieldName="SWI_ID" DataSourceID="ObjSaleUserWeeklyReports"
                                                        OnBeforePerformDataSelect="detailGrid_DataSelect">
                                                        <SettingsText EmptyDataRow="没有数据"></SettingsText>
                                                        <SettingsLoadingPanel Text="正在加载..."></SettingsLoadingPanel>
                                                        <Styles>
                                                            <Header ImageSpacing="5px" SortingImageSpacing="5px" HorizontalAlign="Center">
                                                            </Header>
                                                            <LoadingPanel ImageSpacing="10px">
                                                            </LoadingPanel>
                                                            <AlternatingRow Enabled="True" />
                                                        </Styles>                                                        
                                                        <SettingsBehavior AllowFocusedRow="True" AllowGroup="False" AllowSort="False" />
                                                        <Columns>
                                                            <dxwgv:GridViewDataTextColumn FieldName="SWI_ITEM1" Width="150px" Caption="星期(日期)"
                                                                VisibleIndex="0">
                                                            </dxwgv:GridViewDataTextColumn>
                                                            <dxwgv:GridViewDataTextColumn FieldName="SWI_ITEM2" Width="450px" Caption="当天主要工作内容和拜访用户情况" VisibleIndex="1">                                                  
                                                            </dxwgv:GridViewDataTextColumn>
                                                            <dxwgv:GridViewDataTextColumn FieldName="SWI_ITEM3" Width="150px" Caption="已取得的阶段性成果" VisibleIndex="2">
                                                            </dxwgv:GridViewDataTextColumn>
                                                        </Columns>
                                                        <SettingsDetail IsDetailGrid="true" />
                                                        <SettingsBehavior ColumnResizeMode="Control" AllowFocusedRow="True" AllowGroup="False"
                                                            AllowSort="False" />
                                                        <SettingsPager AlwaysShowPager="True" PageSize="10">
                                                            <AllButton Visible="True">
                                                            </AllButton>
                                                            <Summary AllPagesText="分页{0} - {1} (总{2}条)" Text="当前第{0}页,一共{1}页 (总{2}条)" />
                                                        </SettingsPager>
                                                    </dxwgv:ASPxGridView>
                                                </DetailRow>
                                            </Templates>
                                            <SettingsBehavior ColumnResizeMode="Control" AllowFocusedRow="True" AllowGroup="False"
                                                AllowSort="False" />
                                            <SettingsPager AlwaysShowPager="True" PageSize="15">
                                                <AllButton Visible="True">
                                                </AllButton>
                                                <Summary AllPagesText="分页{0} - {1} (总{2}条)" Text="当前第{0}页,一共{1}页 (总{2}条)" />
                                            </SettingsPager>
                                        </dxwgv:ASPxGridView>
                                    </td>
                                </tr>
                            </table>
                        </dxw:contentcontrol>
                    </ContentCollection>
                </dxtc:TabPage>
            </TabPages>
        </dxtc:ASPxPageControl>
        <asp:ObjectDataSource ID="objSaleUser" runat="server" SelectMethod="GetSaleUserList"
            TypeName="DHC.EAS.Bo.BoWeekReportSummarize"></asp:ObjectDataSource>
        <asp:ObjectDataSource ID="ObjSaleUserWeeklyReports" runat="server" SelectMethod="GetFinishedWeeklyReports"
            TypeName="DHC.EAS.Bo.BoWeekReportSummarize">
            <SelectParameters>
                <asp:SessionParameter Name="saleUserID" SessionField="saleUserID" Type="Object" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </form>
</body>
</html>

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:博客园

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP