0

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.

Edited by Dani: Formatting fixed

3
Contributors
4
Replies
16
Views
4 Years
Discussion Span
Last Post by gahhon
0

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;
 }

Edited by JorgeM

0

This is exactly what I've been looking for.

Thank you very much.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.