1
<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>

In my codebehind, I have

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

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?

1
  • 1
    Do you have autopostback="true" set on this control? You might also want to investigate other ways of doing this, for example jQuery. Commented Dec 9, 2011 at 15:53

1 Answer 1

3

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

Just change it to:

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

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.