2015-01-13 26 views
0

我目前正在從我的第一個列表框中選擇一個值,並基於該值將填充第二個列表框中的值。但是,有些情況下,第一個列表框的值可能不會返回任何內容。我想知道如何在屏幕上顯示文本,如所選值不返回任何內容時的「無數據返回」。這可能嗎?我正在使用sqldatasources這兩個列表框。使用列表框處理來自查詢的空數據

<asp:ListBox ID="SectionItemListBox" DataSourceID="SectionItemSource" runat="server" AutoPostBack="True" DataTextField="SectionItem" DataValueField="SectionItemID" AppendDataBoundItems="False" EnableViewState="True" OnSelectedIndexChanged="SectionItemListBoxSelectedIndexChanged"> 
</asp:ListBox> 


<div style="width:800px; height:auto; overflow:auto"> 
    <asp:ListBox ID="SectionItemInstructionListBox" DataSourceID="SectionItemInstructionSource" runat="server" DataTextField="Instruction" Visible="True" /> 
</div> 

回答

2

我喜歡的東西去...

<div style="width:800px; height:auto; overflow:auto"> 
    <asp:ListBox ID="SectionItemInstructionListBox" DataSourceID="SectionItemInstructionSource" runat="server" DataTextField="Instruction" Visible="True" OnDataBound="SectionItemInstructionListBox_OnDataBound" /> 

    <asp:Panel ID="NoDataReturnedPanel" Visible="false"> 
     No Data Returned 
    </asp:Panel> 
</div> 

protected void SectionItemInstructionListBox_OnDataBound(object sender, EventArgs e) 
{ 
    NoDataReturnedPanel.Visible = SectionItemInstructionListBox.Items.Count == 0; 
    SectionItemInstructionListBox.Visible = SectionItemInstructionListBox.Items.Count != 0; 
} 
+0

感謝它的工作你是天才 – user3339242