我的隐形下拉列表在 Visual Studio 中不再可见
我正在使用 Visual Studio 2010,并且创建了一个网站 (.aspx)。
我有 2 个单选按钮和一个 DropDownList。 我想要一个不可见的下拉列表,每当我单击一个单选按钮时,就会出现下拉列表! 我添加了这样的代码,但没有任何改变,我不明白为什么!
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton1.Checked == true)
DropDownList4.Visible = true;
else
DropDownList4.Visible = false;
}
protected void Page_Load(object sender, EventArgs e)
{
DropDownList4.Visible=false;
}
我得到的唯一的东西是一个不可见的下拉列表,它永远不会变得可见! 我的两个单选按钮都有相同的操作“radiobutton_checkedchanged”..
谢谢!
I am using Visual Studio 2010, and I created a site (.aspx).
I have 2 radiobuttons, and a DropDownList.
I want to have an invisible dropdownlist and whenever I click on the one radiobutton then the downdownlist to appear!
I have added a code like this but nothing changes and I can't understand why!!
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton1.Checked == true)
DropDownList4.Visible = true;
else
DropDownList4.Visible = false;
}
protected void Page_Load(object sender, EventArgs e)
{
DropDownList4.Visible=false;
}
The only thing I am getting, is an invisible dropdownlist than never becomes visible!
Both of my radiobuttons have the same action "radiobutton_checkedchanged" ..
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码没问题,将单选按钮的 AutoPostBack 属性设置为 true,
因为
RadioButton_CheckedChanged(object sender, EventArgs e)
事件在页面加载后发生,它将无需检查!IsPostBack
your code is ok , set AutoPostBack property of radiobutton to true
since
RadioButton_CheckedChanged(object sender, EventArgs e)
events occurs after page loadit will work no need for checking !IsPostBack
修改您的代码如下:
Modify your code as below: