Hi!

I need some help on this. I have the checkbox name chkitems: here's the data:

<asp:CheckBoxList runat="server" ID="chkitems" Font-Names="Tahoma" Font-Size="Smaller"
RepeatColumns="3" RepeatDirection="Horizontal">
 <asp:ListItem Value="1">Item 1</asp:ListItem>
 <asp:ListItem Value="2">Item 2</asp:ListItem>
 <asp:ListItem Value="3">Item 3</asp:ListItem>
 <asp:ListItem Value="4">Item 4</asp:ListItem>
 <asp:ListItem Value="5">Item 5</asp:ListItem>
</asp:CheckBoxList>

Below on this script is the button name "cmdSelectedItems". What I want to do is once I click the button(cmdSelectedItems) It should be automatically checked the Items 1,3 and 5.

Please help me.

Thanks in advance.

Recommended Answers

All 4 Replies

I'd suggest you do this client side, but if you want to handle this server-side...

aspx
<form id="form1" runat="server">
        <div>
            <asp:CheckBoxList runat="server" ID="chkitems" 
                   Font-Names="Tahoma" Font-Size="Smaller"
                    RepeatColumns="3" RepeatDirection="Horizontal">
                <asp:ListItem Value="1">Item 1</asp:ListItem>
                <asp:ListItem Value="2">Item 2</asp:ListItem>
                <asp:ListItem Value="3">Item 3</asp:ListItem>
                <asp:ListItem Value="4">Item 4</asp:ListItem>
                <asp:ListItem Value="5">Item 5</asp:ListItem>
            </asp:CheckBoxList>
            <asp:Button Text="Select Items" runat="server" 
                    ID="cmdSelectedItems" OnClick="cmdSelectedItems_Click" />
        </div>
        </form>
What language are you developing in? C#?
protected void cmdSelectedItems_Click(object sender, EventArgs e)
{
   chkitems.Items.FindByValue("1").Selected = true;
   chkitems.Items.FindByValue("3").Selected = true;
   chkitems.Items.FindByValue("5").Selected = true;
 }

This is exactly what I've been looking for.

Thank you very much.

Glad you solved your issue.

Please kindly mark this thread as solved. Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.