I'm new and working on a project and I'm want to insert radio buttons values into database through c#
here is the code of Unit.aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Unit.aspx.cs" Inherits="Unit" %>
and Unit.aspx.cs source code...........
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)
{
}
}
Please help me ............thanks......

Akhilesh PatelPosted Jan 13, 2012, 2:39 PM
In the form design mode IsActivate contain yes or no.how i can do this......thanks
Satyapriya NayakPosted Jan 13, 2012, 12:06 PM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
DataSet ds;
string str;
protected void B1_Click(object sender, EventArgs e)
{
if (RB1.Checked == true)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "Insert into SS_Mst_Unit(UnitName,IsActive,CDate,CUser,MDate,MUser) values('" + T1.Text + "','" + RB1.Text + "','" + T2.Text + "','" + T3.Text + "','" + T4.Text + "','" + T5.Text + "')";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
}
else if(RB2.Checked==true)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "Insert into SS_Mst_Unit(UnitName,IsActive,CDate,CUser,MDate,MUser) values('" + T1.Text + "','" + RB2.Text + "','" + T2.Text + "','" + T3.Text + "','" + T4.Text + "','" + T5.Text + "')";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
}
}
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;
}
}
}
Thanks
karthik vPosted Jan 13, 2012, 8:44 AM
what is the problem you are facing?