我正在向 ListBox 添加项目,uxSearchList
. 但是,即使后面的代码按预期工作,单击后更改不会反映在uxSearchList
ListBox 中Search
。
我执行以下操作:
- 输入搜索条件 (
uxEsnCheck/Text
,uxLocationList/Text
) - 点击
Search
- (进行中)将搜索结果填充到
uxSearchList
如何uxSearchList
通过我目前拥有的内容填充 ListBox?我的代码如下。
.ASPX.CS
protected void uxSearchParams_Click(object sender, EventArgs e)
{
uxSearchList.Items.Clear();
var selectedSerial = uxEsnText.Text;
var selectedLocation = uxLocationList.Text;
if (!uxEsnText.Enabled)
{
selectedSerial = string.Empty;
}
if (!uxLocationList.Enabled)
{
selectedLocation = string.Empty;
}
if (Page.IsValid)
{
var selectedParams = _presenter.OnSelectionParams(selectedSerial, selectedLocation);
foreach (var param in selectedParams)
{
uxSearchList.Items.Add(param.SerialNumber);
}
}
}
.ASPX
<asp:UpdatePanel ID="uxParamsPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:CheckBox ID="uxEsnCheck" runat="server" CssClass="form-label" Text="Engine Serial Number" OnCheckedChanged="uxEsnCheck_CheckedChanged" AutoPostBack="true" />
<asp:TextBox ID="uxEsnText" runat="server" Enabled="False"/>
<asp:CheckBox ID="uxLocationCheck" runat="server" CssClass="form-label" Text="Location" OnCheckedChanged="uxLocationCheck_CheckedChanged" AutoPostBack="true" />
<asp:DropDownList ID="uxLocationList" runat="server" Enabled="False"/>
<asp:Button ID="uxSearchParams" runat="server" onclick="uxSearchParams_Click" CssClass="form-label" Text="Search" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="uxSearchParams" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="uxEsnCheck" EventName="CheckedChanged" />
<asp:AsyncPostBackTrigger ControlID="uxLocationCheck" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="uxSelectionPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="uxSearchDisplay" runat="server" CssClass="form-label" Text="Search Results" />
<asp:ListBox ID="uxSearchList" runat="server" Width="250px" />
<asp:Label ID="uxMemberDisplay" runat="server" CssClass="form-label" Text="Engine Group Members" />
<asp:ListBox ID="uxMemberList" runat="server" Width="250px" />
<asp:Button ID="uxAdd" runat="server" onclick="uxAdd_Click" Text=">" />
<asp:Button ID="uxRemove" runat="server" onclick="uxRemove_Click" Text="<" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="uxAdd" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="uxRemove" EventName="Click" />
</Triggers>
</asp:UpdatePanel>