Home > DeveloperSection > Forums > how use radio button in asp.net
Pawan kumar
Pawan kumar

Total Post:19

Posted on    March-15-2011 9:28 AM

 ASP.Net ASP.Net 

 1 Reply(s)
 10047  View(s)
Rate this:
sir i want to use radiobutton in .aspx page. and i want to save checked radiobutton data in table.
example-i have take a field like  Sex-(1-Male,2-Female),then i want to saved data in table which is checked

Awadhendra Tiwari

Total Post:126

Posted on    March-15-2011 9:46 AM

Write down following code on aspx page
        <asp:RadioButton ID="rdbMale" GroupName="Gender" Text="Male" runat="server" />
        <asp:RadioButton ID="rdbFemale" GroupName="Gender" Text="Female" runat="server" />
        <asp:Button ID="btnSave" Text="Save Radio Button State" runat="server" OnClick="btn_Click" />

Write down following code on code behind file.

protected void btn_Click(object sender, EventArgs e)
        string gender = "";
        if (rdbMale.Checked)
            gender = rdbMale.Text;
            gender = rdbFemale.Text;
        using (SqlConnection con = new SqlConnection("conString"))
            SqlCommand cmd = new SqlCommand("insert into gender values(@gender)", con);
            cmd.Parameters.Add(new SqlParameter("@gender", gender));
            Response.Write("<script>alert('Status Saved')</script>");
This might be worked for you.

Don't want to miss updates? Please click the below button!

Follow MindStick