Sample Code:How to Use RadioButton for Beginners ?

Sabarimahesh
Posted by Sabarimahesh under ASP.NET category on | Points: 40 | Views : 1259
ASP SOURCE CODE

<asp:RadioButtonList ID="Cmpany" runat="server" >

<asp:ListItem Text="IT" Value="1"></asp:ListItem>

<asp:ListItem Text="NON_IT" Value="2"></asp:ListItem>

<asp:ListItem Text="Acedamy" Value="3"></asp:ListItem>

<asp:ListItem Text="Trainee" Value="4"></asp:ListItem>


</asp:RadioButtonList>


C#
String name="";

string CONS="";

CONS=System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

name=Cmpany.SelectedItem.Text;

SQlConnection con= new SqlConnection(CONS);

Sqlcommand cmmd=new SqlCommand("Sp_CompanyDepatr", con);

cmmd.CommandType = CommandType.StoredProcedure;

cmmd.Parameters.AddWithValue("@name", name);

con.open();

Sqldataadapter Adp= new SqlDataAdapter(cmmd);

cmmd.ExecuteNonQuery();



Sp_CompanyDepatr


CREATE PROCEDURE Sp_CompanyDepatr
@name varchar(50)
as
begin
insert into Table_1 (dept) values(@name)
end

Comments or Responses

Posted by: Self-Innovator on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
It seems to be some where in forum reply...
Posted by: Sabarimahesh on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
Self-Innovator
I used in My Project...

Which Forums....

Any way dotnet Starters will Get Benefit
Posted by: Self-Innovator on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
In dotnetfunda Forums K...How do u pass the value wil u pls rectify and ur code is not working...Kindly chek it before posting
cmmd.Parameters.AddWithValue("@name", name);

Posted by: Sabarimahesh on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
Self-Innovator:

Now i updated Code , plz check it

in that name is a string...

So we are going to pass parameter name to sp;

in that name we are getting selected index text to insert into the database...


Posted by: Self-Innovator on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
Sorry mahesh still not wrking....kindly run in your System once and then Post it... Will u pls Explain where u you are getting the ConnectionString...
 SQlConnection con= new SqlConnection(CONS); 

Posted by: Sabarimahesh on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
i think ur Sqlconnection is the problem.


Please do it:

Write it in Web.config flie

Web.config
<connectionStrings>
<add name="ConnectionString" connectionString="ur connection string" />
</connectionStrings>

Call it in C#
C#
string CONS="";

CONS=System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

Posted by: Self-Innovator on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
Sorry thats not an Error Con.open() statement reqd needs to open the Connection so that commad will get Execute...Chek this now it will work So run in your System before posting it..
String name="";

name=Cmpany.SelectedItem.Text;
SQlConnection con= new SqlConnection(CONS);
Sqlcommand cmmd=new SqlCommand("Sp_CompanyDepatr", con);
cmmd.CommandType = CommandType.StoredProcedure;
cmmd.Parameters.AddWithValue("@name", name);
con.open();
Sqldataadapter Adp= new SqlDataAdapter(cmmd);
cmmd.ExecuteNonQuery();

Posted by: Sabarimahesh on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
String name="";

string CONS="";
CONS=System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
name=Cmpany.SelectedItem.Text;
SQlConnection con= new SqlConnection(CONS);
Sqlcommand cmmd=new SqlCommand("Sp_CompanyDepatr", con);
cmmd.CommandType = CommandType.StoredProcedure;
cmmd.Parameters.AddWithValue("@name", name);
con.open();
Sqldataadapter Adp= new SqlDataAdapter(cmmd);
cmmd.ExecuteNonQuery();


Now its Working
Posted by: Self-Innovator on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
Yes tats wat u need to Chek it Once before posting it...without opening the state of Connection it will throw an exception....
Posted by: Sabarimahesh on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
Ho Thanks
Posted by: Self-Innovator on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
WELLLCOME

Login to post response