获取一个DropDownList来检查asp.net/C#一个复选框 [英] Getting a dropdownlist to check a checkbox in asp.net/C#

查看:174
本文介绍了获取一个DropDownList来检查asp.net/C#一个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<input runat ="server" type ="checkbox" id="helprequest" />     
<label for="helprequest">Help request</label>
<asp:DropDownList ID="options" runat="server" OnSelectedIndexChanged="checkHelpRequest">
    <asp:ListItem Text="Windows"></asp:ListItem>
    <asp:ListItem Text="Macintosh"></asp:ListItem>
    <asp:ListItem Text="Linux"></asp:ListItem>
    <asp:ListItem Text="Other"></asp:ListItem>
</asp:DropDownList>

在我的codebehind,我有

In my codebehind, I have

protected void checkHelpRequest(object sender, EventArgs e)
{
    helprequest.Checked = true;
}

但是,当我选择DropDownList的东西,复选框,没有得到作为托运标记,我怎么当我改变一个DropDownList指数的​​复选框以显示为检查?

But when I select something on the dropdownlist, the checkbox, does not get marked as checked, how do I get the checkbox to appear as checked when I change the index on a dropdownlist?

推荐答案

的DropDownList 没有的AutoPostBack ='真正的'设置。如果不设置此,您的下拉列表将不会回来后,当您更改选定的索引。

Your DropDownList does not have AutoPostBack='true' set. Without setting this, your dropdown will not post back when you change the selected index.

只是将其更改为:

<asp:DropDownList AutoPostBack="true" ID="options" 
      runat="server" OnSelectedIndexChanged="checkHelpRequest">

如果不设置这个,你的 checkHel prequest 方法会继续当你的下拉变化指数,但回发的部分只造成之后调用其他控制,就像一个按钮,或者其他的DropDownList的确实的具有的AutoPostBack集。

Without setting this, your checkHelpRequest method will still be called when your drop down changes index, but only after a postback is caused by some other control, like a button, or another DropDownList that does have AutoPostBack set.

这篇关于获取一个DropDownList来检查asp.net/C#一个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆