5
Answers

insert selected checkbox list data into database

rohit manhas

rohit manhas

14y
15.2k
1
this is my checkbox list......

<asp:CheckBoxList ID="CheckBoxList1" runat="server">
                    <asp:ListItem>Public Tap</asp:ListItem>
                    <asp:ListItem>Well Water</asp:ListItem>
                    <asp:ListItem>Hand Pump</asp:ListItem>
                    <asp:ListItem>Tap Water Within House</asp:ListItem>
</asp:CheckBoxList>

nw i want when i select any of the items ,may be all, from this checkbox list it will be stored into database....
one more thing each listitem had seperate column in database....

like...

publicTap |  WellWater  |  HandPump  |  tap Water.....

i had written this code but it is not working ............

String str="";
 
        for(i=0; i<CheckBoxList1.Items.Count; i++)
        {
            if(CheckBoxList1.Items[i].Selected)       
              {
                 
                  str += CheckBoxList1.Items[i].Text;                
            }
        }

 cmd.Parameters.AddWithValue("@WSTapWater", str);
        cmd.Parameters.AddWithValue("@WSWellWater", str);
        cmd.Parameters.AddWithValue("@WSPublicTap", str);
        cmd.Parameters.AddWithValue("@WSHandPump", str);

plz help me to go through this.......


Answers (5)