2013-04-16 229 views
0

我想隱藏一個Detailsview控件頁面加載的控件值爲0.該Detailsview鏈接到一個SQL數據庫和顯示的值是一個數值從零開始向上。ASP VB.net在頁面加載基於它的值隱藏詳細信息視圖

我已經安裝的控制如下:

<asp:DetailsView Height="25px" Width="60px" ID="dv2cG" runat="server" AutoGenerateRows="False" DataSourceID="ds2cG" BorderWidth="0px" HorizontalAlign="Center" BackColor="#ccd0ff" > 
    <Fields> 
     <asp:BoundField showheader="false" DataField="2cG" HeaderText="2cG" ReadOnly="True" SortExpression="2cG" /> 
    </Fields> 
</asp:DetailsView> 

<asp:SqlDataSource ID="ds2cG" runat="server" ConnectionString="<%$ ConnectionStrings:MaltingsConnectionString %>" SelectCommand="select sum(case when (name = 'English' and ks2en = '2c' and result like 'G') or (name = 'Mathematics' and ks2ma = '2c' and result like 'G') or (not name = 'Mathematics' and not name = 'English' and ks2av = '2c' and result like 'G') then 1 else 0 end) as '2cG' from student join subject on student.upn=subject.upn where @TeachingGroup = 'Select All' AND ([StuYear] = @StuYear) AND ([DataCollection] = @DataCollection) AND ([Name] = @SubjectName) OR @TeachingGroup &lt;&gt; 'Select All' AND ([StuYear] = @StuYear) AND ([DataCollection] = @DataCollection) AND ([Name] = @SubjectName) AND ([TeachingGroup] = @TeachingGroup)"> 

<SelectParameters> 
    <asp:ControlParameter ControlID="DdlTeachingGroup" Name="TeachingGroup" PropertyName="SelectedValue" /> 
    <asp:ControlParameter ControlID="DdlYear" Name="StuYear" PropertyName="SelectedValue" /> 
    <asp:ControlParameter ControlID="ddlDataCollection" Name="DataCollection" PropertyName="SelectedValue" /> 
    <asp:ControlParameter ControlID="DdlSubject" Name="SubjectName" PropertyName="SelectedValue" /> 
</SelectParameters> 

我已經寫以下簡單的程序:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    'G column - sets dataitem to visible false where the dataitem equal 0 
    If dv2cG.DataItem = 0 Then 
     dv2cG.Visible = False 
    Else 
     dv2cG.Visible = True 
    End If 

End Sub 

這成功地隱藏在DetailsView。但是,即使控件中的值不等於1,也是如此。

感謝您的閱讀。

回答

0

我在解決這個問題時解決了這個問題here

我在sql命令中使用了nullif()函數,例如

select nullif(sum(case when.....then 1 else 0 end),0) as '2cG' 
相關問題