c# - 如何更改下拉列表中的信息
问题描述
因此,如果您选择不同的单选按钮,我想制作一个显示新信息的下拉列表。我正在苦苦挣扎。例如,如果选择单选按钮 1,则保管箱中的信息必须更改为爆米花和糖果。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
margin-left: 18px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButton1_CheckedChanged" Text="Day" />
</div>
<asp:RadioButton ID="RadioButton2" runat="server" Text="Night" />
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Cream Soda</asp:ListItem>
<asp:ListItem>coke</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" CssClass="auto-style1" Width="139px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Seat No:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="140px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Height="20px" Text="Add Choice" />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
</form>
</body>
</html>
解决方案
您必须在 RadioButton 上定义 autopostback="true",然后您需要在代码隐藏中处理选定的值,并使用新的项目列表重新填充下拉列表。
Page-Cycle 会是这样的
- Page_Load
- RadioButton2_Changed
- Page_LoadComplete
因此,请确保在 RadioButton2_Changed 或 Page_LoadComplete 中设置新内容。如果您尝试在 Page_Load 中执行此操作,您将拥有单选按钮的旧值,并且效果不佳...
推荐阅读
- python - Python 等效于 PHP 的 array_push?
- java - 处理字符串 Linkedlist 以从文本文件中删除节点
- reactjs - 使用 reactjs useState 时出现错误
- c++ - 如何在 Sublime Text 中使用 Mingw 和构建系统
- flutter - Flutter 表日历事件列表刷新
- cpu-architecture - 对于常量除数,如何在不支持除法指令的情况下使用快速除法运算?
- c++ - 我如何显示所有在第 8 个基数(数字基数为 8?)中具有 4 位表示的数字?
- python - shutil.copy2 给出“SameFileError” altho 文件根本不一样 - 为什么?
- c++ - LLVM C++ API 是否比构建 IR 文件并提供给 llc 的字符串更好?
- python - 如何从 numpy.fft.rfft 返回 float32 值?