Click here to Skip to main content
Sign Up to vote bad
good
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 - 19:57
lalitkr1.3K
Edited 5 Feb '13 - 20:02


1 solution

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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 414
1 Arun Vasu 253
2 OriginalGriff 190
3 CPallini 163
4 Aarti Meswania 158
0 Sergey Alexandrovich Kryukov 10,169
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid