Click here to Skip to main content
15,885,018 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,

I have list box in my aspx page as
XML
<asp:CheckBoxList ID="bookingBox" Width="300px" runat="server" RepeatDirection="Horizontal"
                                   AutoPostBack="True"
                                   onselectedindexchanged="bookingBox_SelectedIndexChanged">
                                   <asp:ListItem Selected="True">Hotel</asp:ListItem>
                                   <asp:ListItem>Tour</asp:ListItem>
                               </asp:CheckBoxList>

code behind aspx is as:-

protected void bookingBox_SelectedIndexChanged(object sender, EventArgs e)
   {
       if (bookingBox.SelectedValue == "Hotel")
       {

           HotelPanel.Visible = true;
           TourPanel.Visible = false;

       }
       else if (bookingBox.SelectedValue == "Tour")
       {
           HotelPanel.Visible = false;
           TourPanel.Visible = true;
       }
       else {
           HotelPanel.Visible = true;
           TourPanel.Visible = false;
       }
   }

their is two panel one for hotel booking and other for tour booking. when some one want to book hotel then hotel panel is visible by checking check box for hotel and for booking tour then tour panel will be visible by checking check box for tour. that works fine but the main problem is that when both are checked then both panel should become visible. but their is no option how to set condition for it.

so please help my how to set condition when both are checked.

thanks
balwant
Posted
Updated 14-Apr-11 5:39am
v2

1 solution

In your case, where only two items are available this will work

if(bookingBox.SelectedItems.Count == 2)


With only two items there is really no need to use a CheckBoxList, you are applying an unnecessarily complicating the design and making it more difficult to code.
 
Share this answer
 
Comments
Espen Harlinn 14-Apr-11 16:53pm    
Good points, my 5
Balwant.mnd 14-Apr-11 23:43pm    
Thanks for your answer and reply. you said above that CheckBoxList makes design complicated so instead of it what control i had used.
[no name] 15-Apr-11 8:08am    
You only have two checkboxes. A CheckBoxList is overkill, just use the checkboxes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900