如何在显示中隐藏下拉列表中的值0

huangapple go评论80阅读模式
英文:

How to hide value 0 of drop-down list in display

问题

我的下拉列表有值0---请选择口味---,和1红丝绒

<asp:DropDownList ID="Flavorddlist" runat="server">
<asp:ListItem Value="0">--- 请选择口味 --</asp:ListItem>
<asp:ListItem Value="1">红丝绒</asp:ListItem>
</asp:DropDownList>
lblFlavor.Text = Flavorddlist.SelectedItem.Text;

显示应为:

口味: ---请选择口味---

如果我选择值0

当我点击显示按钮时,我不想显示值0。如何在下拉框的值为0时隐藏显示呢?

我不想在下拉列表中隐藏它,我只想在选择了值后隐藏它在显示中。

英文:

My Dropdownlist has value 0 → ---Please Select Flavor---, and 1 → Red velvet

<asp:DropDownList ID="Flavorddlist" runat="server">
<asp:ListItem Value="0">--- Please Select Flavor --</asp:ListItem>
<asp:ListItem Value="1">Red Velvet</asp:ListItem>
</asp:DropDownList>
lblFlavor.Text = Flavorddlist.SelectedItem.Text;

The display should be:

Flavor: ---Please Select Flavor---

if I choose the value 0.

When I click the display button, I don't want it to display the value 0. How can I hide the display when the dropdown's value is 0?

I don't want to hide it in Dropdown list, I just want to hide it in the display once a value is chosen.

答案1

得分: 0

要在所选值为0("---请选择口味---")时隐藏显示,您可以在设置lblFlavor.Text之前在C#代码中添加条件检查。如果所选值为0,您可以将lblFlavor.Text设置为空字符串,从而有效地隐藏显示。

if (Flavorddlist.SelectedValue == "0")
{
    lblFlavor.Text = ""; // 当所选值为0时隐藏显示
}
else
{
    lblFlavor.Text = Flavorddlist.SelectedItem.Text;
}
英文:

To hide the display when the selected value is 0 ("--- Please Select Flavor ---"), you can add a conditional check in your C# code before setting the lblFlavor.Text. If the selected value is 0, you can set the lblFlavor.Text to an empty string, effectively hiding the display.

if (Flavorddlist.SelectedValue == "0")
{
    lblFlavor.Text = ""; // Hide the display when the selected value is 0
}
else
{
    lblFlavor.Text = Flavorddlist.SelectedItem.Text;
}

huangapple
  • 本文由 发表于 2023年7月31日 21:47:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804263.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定