Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear sir,

i worked on a asp project. I need a small help from you. I have two radio button in my page as like YES & NO. So in that situation NO is always selected as my default value and when I clicked on YES and insert the record after that Radio button should selected as NO. I have written the code as

C#
protected void btnSaveprint_Click(object sender, EventArgs e)
   {
   cmd.CommandText = "INSERT INTO tbl_healthrecord (sl_no,entry_date,factory_name,chkValue)
   values ('" + code + "','" + txtDateentry.Text + "','" + txtFactoryName.Text.ToUpper() + "','"+chk+"')";
cmd.Connection = con;
                cmd.ExecuteNonQuery();
                con.Close();
 rdbNo.Checked=true;
} 


But it does not work. So plz tell some solution for me.
Thanks & Regards
Bigyan Ranjan Sahoo
Posted
Updated 25-Dec-14 8:29am
v4
Comments
DamithSL 25-Dec-14 11:46am    
update the question with Data() method code
DamithSL 25-Dec-14 11:52am    
for given information we can't tell what is the issue, you know that we can't see your code or read your mind, you better include small sample code to recreate the issue, make sure others can recreate the issue by running your sample code.
have you debug and check whether your application execute the line where you set the value of "rdbNo.Checked"?
Sergey Alexandrovich Kryukov 25-Dec-14 12:06pm    
RadioButton? Which one? Full type name, please.
—SA
bigyan sahoo 25-Dec-14 12:09pm    
YES & NO there are two radio button & I want to Select default value
NO after insert data.
bigyan sahoo 25-Dec-14 12:34pm    
Plz answer the question ..

1 solution

I have done it..
I write the code in a method and call it after insert data.
C#
public void rdbData()
   {
       rdb_Yes.Checked = true;
       rdb_No.Checked = false;


}

C#
protected void btnSaveprint_Click(object sender, EventArgs e)
   {

cmd.CommandText = "INSERT INTO tbl_healthrecord (sl_no,entry_date,factory_name,chkValue)
values ('" + code + "','" + txtDateentry.Text + "','" + txtFactoryName.Text.ToUpper() + "','"+chk+"')";
Collapse | Copy Code

cmd.Connection = con;
                cmd.ExecuteNonQuery();
                con.Close();



rdbData();
}
 
Share this answer
 
Comments
Philippe Mori 25-Dec-14 18:23pm    
In that example you set the rdbYes button as checked while in the question you set the rdbNo button as checked. Thus which one of the button you want checked? In your question, you said that you want NO button checked. You have to be coherent by yourself. Otherwise, nobody will be able to help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900