0

Hi, I need help for this problem that i'm trying to solve for a while (i'm Using ASP.net and C#). How do i submit the values from selected checkbox lists into database using c#....


Here's the code:
..........................................................................

<asp:CheckBoxList ID="CheckBoxList1" runat="server" Font-Bold="False" 
                    Font-Names="Vrinda" Width="338px" style="text-align: left">
                    <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>


 <asp:CheckBoxList ID="CheckBoxList2" runat="server" Font-Bold="False" 
                    Font-Names="Vrinda">
                    <asp:ListItem>Within the House</asp:ListItem>
                    <asp:ListItem>Neighbour's House</asp:ListItem>
                    <asp:ListItem>Within 50 Meters</asp:ListItem>
                    <asp:ListItem>More than 50 Meters</asp:ListItem>
                </asp:CheckBoxList>

................................

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by rohitmanhas_12
0

Add an event handler

OnSelectedIndexChanged="Check"

Now in the Check function .Add this

for(i=0;i<=CheckBoxList1.Items.Count-1;i++)
{
      if(CheckBoxList1.Items[i].Selected))
        //insert into database
}
0

Hi, I need help for this problem that i'm trying to solve for a while (i'm Using ASP.net and C#). How do i submit the values from selected checkbox lists into database using c#....


Here's the code:
..........................................................................

<asp:CheckBoxList ID="CheckBoxList1" runat="server" Font-Bold="False" 
                    Font-Names="Vrinda" Width="338px" style="text-align: left">
                    <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>


 <asp:CheckBoxList ID="CheckBoxList2" runat="server" Font-Bold="False" 
                    Font-Names="Vrinda">
                    <asp:ListItem>Within the House</asp:ListItem>
                    <asp:ListItem>Neighbour's House</asp:ListItem>
                    <asp:ListItem>Within 50 Meters</asp:ListItem>
                    <asp:ListItem>More than 50 Meters</asp:ListItem>
                </asp:CheckBoxList>

................................

Hi try the below. It works...

foreach (ListItem litem in CheckBoxList1.Items)
{
if (litem.Selected)
//Insert in to database
}

0

i have written this code but it is not working.....
plz help me how to insert the selected data from check box list into database...
and one more thing,each list item have separate column in database......
like....

                      |                       |                       |                         |
WSTapWater | WSWellWater | WSPublicTap | WSHandPump  |          
                      |                       |                       |                         |

c#,code.............

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

Edited by mike_2000_17: Fixed formatting

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.