Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<asp:RadioButtonList ID="Rad" runat="server"
                        onselectedindexchanged="RadioButtonList2_SelectedIndexChanged"
                        RepeatDirection="Horizontal">
                        <asp:ListItem Value="0">c</asp:ListItem>
                        <asp:ListItem Value="1">a</asp:ListItem>
                        <asp:ListItem Value="0">c</asp:ListItem>
                    </asp:RadioButtonList>

c# code:
C#
protected void  RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)
{
    RadioButton rb = sender as RadioButton;
    if (rb != null)
    {
        if (rb.Checked)
        {

            sqlcon.Open();
            SqlCommand sqlcom = new SqlCommand("insert into rd_table(radio) values('" + Rad.SelectedValue + "')", sqlcon);
            sqlcom.ExecuteNonQuery();
            sqlcon.Close();
        }
    }

}

It does not insert in sqlserver,,plz modified these code
Posted
Updated 11-Apr-13 19:37pm
v2
Comments
PrashantSonewane 12-Apr-13 1:23am    
Are you getting any error?
Aarti Meswania 12-Apr-13 1:34am    
unclear question
what is exact problem?
Member 9959371 12-Apr-13 1:36am    
it does not insert value in server(database),,plz modified
Aarti Meswania 12-Apr-13 1:39am    
it depends...
1st connection is opened successfully?
2nd check query it should not give error, and if it is throwing error then mention that error then we can help you :)
rmksiva 12-Apr-13 1:41am    
Can you mention DB Datatype for "radio" Field in Insert Query IF Your DB Type is MS SQL SEVER and Datatype of "radio" is bit ! Then Please check Below solution !

C# Code

C#
protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlConnection sqlcon = new SqlConnection("Your Connection String Here");
            for (int i = 0; i < Rad.Items.Count; i++)
            {
                    if (Rad.Items[i] != null && Rad.Items[i].Selected)
                    {
                        sqlcon.Open();
                        SqlCommand sqlcom = new SqlCommand("insert into rd_table(radio) values('" + Rad.SelectedValue + "')", sqlcon);
                        sqlcom.ExecuteNonQuery();
                        sqlcon.Close();
                        break;
                    }
               }
        }



HTML Code

XML
<asp:RadioButtonList ID="Rad" runat="server" OnSelectedIndexChanged="RadioButtonList2_SelectedIndexChanged"
       RepeatDirection="Horizontal" AutoPostBack="true">
       <asp:ListItem Value="0">c</asp:ListItem>
       <asp:ListItem Value="1">a</asp:ListItem>
       <asp:ListItem Value="0">c</asp:ListItem>
   </asp:RadioButtonList>



Thanks,
Prashant
Mark Solution if this work for you!
 
Share this answer
 
sqlcon.Open();

SqlCommand sqlcom = new SqlCommand("insert into rd_table(radio) values(" + ((Rad.SelectedValue) ? 1 :0)  + ")", sqlcon);

sqlcom.ExecuteNonQuery();

sqlcon.Close();
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900