1
Answer

How to insert radio button control value into dabase

Akhilesh Patel

Akhilesh Patel

12y
1.9k
1
Hi.....

        I'm new and working on a project and want to inserting the radio button values into database. I did try many times but can't succeed. Please help me.............

The designe page code os unit.aspx  is here........

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Unit.aspx.cs" Inherits="Unit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            height: 28px;
        }
    </style>
        <script runat="server">
            protected void radiobutton_checkedchange(object sender, System.EventArgs e)
            {
                if (RB1.Checked == true)
                {
                    Label1.Text = "You select Yes";
                }
                else
                {
                    Label1.Text = "Please select Yes or No.";
                }
                if (RB2.Checked == true)
                {
                    Label1.Text = "You select No";
                }
                else
                {
                    Label1.Text = "Please select Yes or No.";
                }
            }
   
       
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <table border="1" width="1241" cellspacing="0" cellpadding="2">
    <tr>
        <td colspan="2" bgcolor="#008000">&nbsp;<br>
&nbsp; <font face="Arial" size="4" color="#FFFFFF">Stores &amp; Inventory Management
        System</font><br>
        <br>
        <br>
        <br>
        <br>
&nbsp;</td>
    </tr>
    <tr>
        <td width="260" bgcolor="#008000" height="25" colspan="7"><b>
        <font color="#FFFFFF" face="Arial" size="4">Unit Master Entry</font></b></td>
       
    </tr>
    <tr>
        <td bgcolor="#008000" class="style2">Unit's Name</td>
        <td bgcolor="#008000" width="975" class="style1">
        <asp:TextBox ID="T1" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
        <td bgcolor="#008000" class="style2">C Date </td>
        <td bgcolor="#008000" width="975" class="style1">
        <asp:TextBox ID="T2" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
        <td bgcolor="#008000" class="style2">C Client</td>
        <td bgcolor="#008000" width="975" class="style1">
        <asp:TextBox ID="T3" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
        <td bgcolor="#008000" class="style2">M Date</td>
        <td bgcolor="#008000" width="975" class="style1">
        <asp:TextBox ID="T4" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
        <td bgcolor="#008000" class="style1">M Client</td>
        <td bgcolor="#008000" width="975" class="style1">
        <asp:TextBox ID="T5" runat="server"></asp:TextBox></td>
    </tr>
     
      <tr>
        <td bgcolor="#008000" class="style2">Is Activate</td>
        <td bgcolor="#008000" width="975" class="style1">
            <asp:RadioButton ID="RB1" runat="server" Text="Yes"
                oncheckedchanged="RB1_CheckedChanged" AutoPostBack="True" GroupName="x" />
&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:RadioButton ID="RB2" runat="server" Text="No"
                oncheckedchanged="RB2_CheckedChanged" AutoPostBack="True" GroupName="x"/>
        &nbsp;&nbsp;
           
        </td>
    </tr>
   
    <tr>
        <td bgcolor="#008000" class="style2">
        <td width="975" bgcolor="#008000">
        <asp:Button ID="B1" runat="server" Text="Save" onclick="B1_Click" />
        &nbsp;
        <asp:Button ID="B2" runat="server" Text="Reset" onclick="B2_Click" />
        </td>
        </td>
    </tr>
    <tr>
        <td width="100%" colspan="2" bgcolor="#008000">
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
&nbsp;</td>
    </tr>
    <tr>
        <td width="100%" colspan="2" bgcolor="#008000">
        <font face="Arial" size="4" color="#FFFFFF">Demo
        Version 1.0<br>
        Copy Right, All Right Reserved 2011</font></td>
    </tr>
</table>
    </form>
</body>
</html>


and the source code of unit.aspx.cs is ................

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;

public partial class Unit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void B1_Click(object sender, EventArgs e)
    {
        string conn = "Data Source=SVPSL-PC; Initial Catalog=SUNBEAMSCHOOL; User Id=sa; Password=sa@1234;";
        SqlConnection con = new SqlConnection(conn);
        con.Open();
        string str;
       
       
        if(RB1.Checked==true)
        {
            str = Convert.ToString(1);
        }
        else
            if(RB2.Checked==true)
            {
                str = Convert.ToString(0);
            }

        string qur = "Insert into SS_Mst_Unit(UnitName,IsActive,CDate,CUser,MDate,MUser) values('" + T1.Text + "','" + T2.Text + "','" + T3.Text + "','" + T4.Text + "','" + T5.Text + "')";
         SqlCommand cmd = new SqlCommand(qur, con);
         cmd.ExecuteNonQuery();
         con.Close();
    }

    private string BitConverter(string str)
    {
        throw new NotImplementedException();
    }
    protected void B2_Click(object sender, EventArgs e)
    {
        T1.Text = "";
        T2.Text = "";
        T3.Text = "";
        T4.Text = "";
        T5.Text = "";
        //T6.Text = "";
        RB1.Checked = false;
        RB2.Checked = false;
    }
    protected void RB1_CheckedChanged(object sender, EventArgs e)
    {

    }
    protected void RB2_CheckedChanged(object sender, EventArgs e)
    {

    }
}
Answers (1)