2015-01-13 4 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