how to use radio button in placeholder
-
I have my radio button declare as Dim optMulChoice As New RadioButton() Dim optTrueFalse As New RadioButton() optMulChoice.Text = "Multiple Answer" optMulChoice.GroupName = "rbtType" optMulChoice.ID = "rbtMulChoice" optMulChoice.Checked = True plhHolder.Controls.Add(optMulChoice) optTrueFalse.Text = "True/False" optTrueFalse.GroupName = "rbtType" optTrueFalse.ID = "rbtTrueFalse" plhHolder.Controls.Add(optTrueFalse) which it will keep at place holder. now I will like to insert the selected value into my database when 'ADD' button click. myCommand = New SqlCommand("INSERT INTO t_quiz (q_type) VALUES (@type)", myConnection) myCommand.Parameters.Add("@type", SqlDbType.Bit, 1).Value = rbtType.selectedItem.value But, it showing rbtType is not declare. How am I going to get the value of my selected radio button? What is the correct way to do it?
-
I have my radio button declare as Dim optMulChoice As New RadioButton() Dim optTrueFalse As New RadioButton() optMulChoice.Text = "Multiple Answer" optMulChoice.GroupName = "rbtType" optMulChoice.ID = "rbtMulChoice" optMulChoice.Checked = True plhHolder.Controls.Add(optMulChoice) optTrueFalse.Text = "True/False" optTrueFalse.GroupName = "rbtType" optTrueFalse.ID = "rbtTrueFalse" plhHolder.Controls.Add(optTrueFalse) which it will keep at place holder. now I will like to insert the selected value into my database when 'ADD' button click. myCommand = New SqlCommand("INSERT INTO t_quiz (q_type) VALUES (@type)", myConnection) myCommand.Parameters.Add("@type", SqlDbType.Bit, 1).Value = rbtType.selectedItem.value But, it showing rbtType is not declare. How am I going to get the value of my selected radio button? What is the correct way to do it?
Declare the RadioButtons at the class level and create the instance where it is needed. For e.g(i am writing this in C#) Class ClassName { RadioButton optMulChoice; //declare it here private void Page_Load(object sender, System.EventArgs e) { optMulChoice = new RadioButton(); ..... .... ////your code goes here } private void Button1_Click(object sender, System.EventArgs e) { myCommand = New SqlCommand("INSERT INTO t_quiz (q_type) VALUES (@type)", myConnection); myCommand.Parameters.Add("@type", SqlDbType.Bit, 1).Value =rbtType.SelectedItem .Value; } } Naveen G