Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET
<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:
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 11-Apr-13 20:15pm
Edited 11-Apr-13 20:37pm
v2
Comments
PrashantSonewane at 12-Apr-13 1:23am
   
Are you getting any error?
Aarti Meswania at 12-Apr-13 1:34am
   
unclear question
what is exact problem?
Member 9959371 at 12-Apr-13 1:36am
   
it does not insert value in server(database),,plz modified
Aarti Meswania at 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 at 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 !
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

C# Code
 
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
 
<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!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 Marcin Kozub 265
1 Richard MacCutchan 239
2 OriginalGriff 208
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 12 Apr 2013
Copyright © CodeProject, 1999-2014
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