我目前正在从我的第一个列表框中选择一个值,并根据该值在第二个列表框中填充值。但是,有时第一个列表框中的值可能不会返回任何内容。我想知道如何在屏幕上显示文字,例如"没有数据返回"如果所选值没有返回任何内容。这可能吗?我正在为两个列表框使用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>
答案 0 :(得分: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;
}