HOW USE RADIO BUTTON IN ASP.NET

Pawan kumar

Total Post:19

Points:133
Posted by  Pawan kumar
 10111  View(s)
Ratings:
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
  1. Awadhendra Tiwari

    Post:126

    Points:882
    Re: how use radio button in asp.net

    Write down following code on aspx page
    <div>
            <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" />
    </div>

    Write down following code on code behind file.

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!