利用ASPxGridView制作报表
<dx:ASPxGridView ID="grdProductivity" runat="server" AutoGenerateColumns="False" KeyFieldName="Work_Cell_Code" SkinID="ASPxGridViewSkin"
OnDetailRowExpandedChanged="grdProductivity_DetailRowExpandedChanged" //子表展开时触发
OnCustomUnboundColumnData="grdProductivity_OnCustomUnboundColumnData" //动态序号添加
OnPageIndexChanged="grdProductivity_OnPageIndexChanged"
OnPageSizeChanged="grdProductivity_OnPageSizeChanged"
OnBeforeColumnSortingGrouping="grdProductivity_OnBeforeColumnSortingGrouping" //点击列排序 发生拖拽时触发
OnCustomColumnGroup="grdProductivity_OnCustomColumnGroup"
OnCustomColumnSort="grdProductivity_OnCustomColumnSort">
<Columns>
<dx:GridViewDataTextColumn VisibleIndex="0" Caption="序号" FieldName="hh" UnboundType="Integer" Name="hh" Width="5px">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn VisibleIndex="1" FieldName="Production_Line_Desc" Caption="生产线名称">
</dx:GridViewDataTextColumn>
</Columns>
<Styles>
<Header ForeColor="#697a8a" Font-Bold="True" Font-Size="15px" BackColor="#EFF2F7" Border-BorderColor="#e3eae7"></Header>
</Styles>
<SettingsDetail ShowDetailRow="True"></SettingsDetail>
<Templates>
<DetailRow>
<dx:ASPxGridView runat="server" ID="gv_detail" AutoGenerateColumns="false" SkinID="DetailASPxGridViewSkin" OnCustomUnboundColumnData="gv_detail_OnCustomUnboundColumnData">
<Columns>
<dx:GridViewDataTextColumn VisibleIndex="0" FieldName="hh" Caption="序号" UnboundType="Integer" Name="hh" Width="5px">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn VisibleIndex="1" FieldName="Production_Line_Desc" Caption="生产线名称">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
</DetailRow>
</Templates>
</dx:ASPxGridView>
<dx:ASPxGridViewExporter ID="dxgvExport" runat="server" GridViewID="grdProductivity"></dx:ASPxGridViewExporter> / /导出到xlsx
主子表:报表
主表ID: <dx:ASPxGridView ID="grdProductivity"...>
子表ID: <dx:ASPxGridView ID="gv_detail"...>
加子表时,一定要加上以下代码: <SettingsDetail ShowDetailRow="True"></SettingsDetail>
<Templates>
<DetailRow>
显示的列:<Columns>
<dx:GridViewDataTextColumn VisibleIndex="0" FieldName="hh" Caption="序号" UnboundType="Integer" Name="hh" Width="5px">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn VisibleIndex="1" FieldName="Production_Line_Desc" Caption="生产线名称">
</dx:GridViewDataTextColumn>
</Columns>
//其中FieldName一定是sql查出来的字段,显示的列名为:Caption="生产线名称"
设置标题的样式;
<Styles>
<Header ForeColor="#697a8a" Font-Bold="True" Font-Size="15px" BackColor="#EFF2F7" Border-BorderColor="#e3eae7"></Header>
</Styles>
原文地址:https://www.cnblogs.com/newsf/p/qq499513945.html