I’m using APS.net and c#
I have a RadioButtonList, DropDownList, Button and label in a ModalPopupExtender.
<ajaxToolkit:ModalPopupExtender ID="mpeDirector_Accept_or_Reject_Overtime" runat="server" PopupControlID="pModal_Popup_Director_Accept_or_Reject_Overtime" TargetControlID="btnModal_Popup_Dummy_TargetControlID"
BackgroundCssClass="modalBackground" DropShadow="True">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="pModal_Popup_Director_Accept_or_Reject_Overtime" runat="server" CssClass="modalPopup" BackColor="#FFFFCC" BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" style="display:none;">
<asp:Label ID="lbModal_Popup_Director_Accept_or_Reject_Overtime_Message" runat="server" Font-Names="Arial" ForeColor="Red" Font-Bold="True">"Director Accept/Reject" Over Time?</asp:Label>
<asp:RadioButtonList ID="rblDirector_Accept_or_Reject" runat="server" RepeatDirection="Horizontal" >
<asp:ListItem ID="liDirector_Accept" Text="Accept" Tag="1" ></asp:ListItem>
<asp:ListItem ID="liDirector_Reject" Text="Reject" Tag="2" ></asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
<div>
<asp:Label ID="lbEmployee_Hourly_Rate_Multiplier" runat="server" Font-Names="Arial" Enabled="True" ForeColor="Black" Font-Bold="True">Hourly Rate:</asp:Label>
</asp:DropDownList>
<asp:UpdatePanel ID="udpModal_Popup_Director_Authorise" runat="server" Width="430px">
</asp:UpdatePanel>
</div>
<hr></hr>
<asp:Button ID="btnModal_Popup_Director_Authorise_Cancel" runat="server" Text="Cancel" Width="174px" CausesValidation="False"/>
</asp:Panel>
How do I create an event on the DropDownList when I can then make a label visible or not based on what ListItem was selected.
Something like this:-
Switch (DropDownList.SelectedItemIndex)
{
case "Accept":
{
lbModal_Popup_Director_Accept_or_Reject_Overtime_Message.Visible = true;
break
}
case "Reject":
{
lbModal_Popup_Director_Accept_or_Reject_Overtime_Message.Visible = false;
break
}
}
Thanks
2
Answers
Using a Ajax ModalPopupExtender and using JQuery I've put this example together. A Label and a DropDownlist are visible depending on which ListItem is selected on the RadioButtonList.
HTML:-
c#:-
You can do it via a
SelectedIndexChanged
event, for example: https://www.aspsnippets.com/Articles/1593/ASPNet-DropDownList-SelectedIndexChanged-event-example-in-C-and-VBNet/ likeYou will also need
runat="server"
andOnSelectedIndexChanged="OnSelectedIndexChanged"
in the markup of yourDropDownList
.