Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi sir,

in my web app i am taken one dropdownlist, button and chekboxList controls. and in dropdownlist items are Red, Blue, Green.

and in checkedlistbox i take items are

XML
<asp:CheckBoxList ID="CheckBoxList1" runat="Server">
        <asp:ListItem Text="Red" Value="red"></asp:ListItem>
        <asp:ListItem Text="Blue" Value="blue"></asp:ListItem>
        <asp:ListItem Text="Green" Value="green"></asp:ListItem>
    </asp:CheckBoxList>



my aim is when i am selecting Red item in dropdownlist and i click button that time Red checkbox is selected. similarly to all

please give me a solution and please give a some sample code todo this.

Thanks
Posted

Use the below code .. the array list will hold the Selected check box value from checkbox list control

C#
ArrayList arrList = new ArrayList();
   for(int i=0;i<=CheckBoxList1.Items.Count -1;i++)
    {
        if (CheckBoxList1.Items[i].Selected)
        {
            arrList.Add(CheckBoxList1.Items[i].Value);
        }


}
 
Share this answer
 
v2
check this
C#
protected void Button1_Click(object sender, EventArgs e)
   {
       for (int i = 0; i < CheckBoxList1.Items.Count; i++)
       {
           if (CheckBoxList1.Items[i].ToString() == DropDownList1.SelectedItem.Text)
           {
               CheckBoxList1.Items[i].Selected = true;
               break;
           }
       }
   }
 
Share this answer
 

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