当ASPxSummaryItem中的值为0时,隐藏ASPxGridView中的列

时间:2018-03-02 17:50:54

标签: c# asp.net tsql devexpress

这是我的gridview

<dx:ASPxGridView ID="GridViewID" runat="server" DataSourceID="SourceMain" ClientInstanceName="Grid" SettingsPager-mode="ShowAllRecords" OnHtmlDataCellPrepared="ASPxGridView1_HtmlDataCellPrepared">
 <Columns>
     <dx:GridViewDataTextColumn FieldName="TrackOutDate" VisibleIndex="1" Visible="True"><PropertiesTextEdit DisplayFormatString="MM/dd/yyyy"></PropertiesTextEdit></dx:GridViewDataTextColumn>
     <dx:GridViewDataTextColumn FieldName="LotID" VisibleIndex="2" Visible="True"></dx:GridViewDataTextColumn>
     <dx:GridViewDataTextColumn FieldName="Qty_IN" VisibleIndex="11" Visible="True"></dx:GridViewDataTextColumn>
     <dx:GridViewDataTextColumn FieldName="HX" VisibleIndex="12" Visible="True"></dx:GridViewDataTextColumn>
     <dx:GridViewDataTextColumn FieldName="NA" VisibleIndex="13" Visible="True"></dx:GridViewDataTextColumn>
 </Columns>
    <Settings ShowFooter="true" />
    <TotalSummary> 
    <dx:ASPxSummaryItem FieldName="Qty_IN" SummaryType="Sum" DisplayFormat="{0}" Tag="1" ShowInColumn="Qty_IN"  />
    <dx:ASPxSummaryItem FieldName="HX" SummaryType="Sum" DisplayFormat="{0}"/>
    <dx:ASPxSummaryItem FieldName="NA" SummaryType="Sum" DisplayFormat="{0}"/>
    </TotalSummary>
</dx:ASPxGridView>

这是填充gridview的代码:

protected void SourceMain_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
    lote = getLot();
    device = getDevice();
    stage = getStage();
    location = getLocation();
    equipment = getEquipment();
    SD = Convert.ToDateTime(getStartDate());
    ED = Convert.ToDateTime(getEndtDate());

    MetricsPortal.DAL.ReportsDataClassesDataContext dataContext = new MetricsPortal.DAL.ReportsDataClassesDataContext();
    e.Result = (from items in dataContext.CalculateDailyYieldequipmentParam(lote,device,stage,location,equipment,SD,ED,Evaluation())
                orderby items.TrackOutDate ascending, items.GRANDTOTAL1 descending
                //where items.GRANDTOTAL1 > 0
                select items).Distinct();

}//source Main

当这些列的总摘要为0时,是否可以删除或隐藏列?

Ex:enter image description here

在黄色列中,值为0,在这种情况下我可以隐藏此列吗?当不是0时只显示列?

1 个答案:

答案 0 :(得分:0)

实际上选择的事件更适合GridView1.Columns[yourcolumnindex].Visible = false; 和列将消失。