Click here to Skip to main content
12,749,596 members (31,413 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
I have checkboxlist having values as A , B , C , D now and user in the textbox now when i click on the save button the value of the checkboxlist whichever is selected like 1 , b , c or a , b , d like combination
the value gets saved into database seprately in each row against the user or value entered in the textbox

and how can i get back the value when i click on the edit button the vale gets back to the respective checkbox
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
                        RepeatDirection="Horizontal">
                        <asp:ListItem>Sun</asp:ListItem>
                        <asp:ListItem>Mon</asp:ListItem>
                        <asp:ListItem>Tue</asp:ListItem>
                        <asp:ListItem>Wed</asp:ListItem>
                        <asp:ListItem>Thu</asp:ListItem>
                        <asp:ListItem>Fri</asp:ListItem>
                        <asp:ListItem>Sat</asp:ListItem>
                        <asp:ListItem>Sun</asp:ListItem>
                    </asp:CheckBoxList>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click"
              Width="82px" />
Posted 5-Feb-13 20:57pm
lalitkr1.8K
Updated 5-Feb-13 21:02pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hello Sandeep

You can implement your button event handler like below to get all selected items Text -

protected void Button1_Click(object sender, EventArgs e)
        {
            List<string> lstItems = new List<string>();
            foreach (ListItem listItem in CheckBoxList1.Items)
            {
                if (listItem.Selected)
                {
                    lstItems.Add(listItem.Text);
                }

            }
        }



//then you can implement database insertion logic

Thanks
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100