I am using radiobutton list with 3 list item, after select one list item its only take null value in database
cmd.Parameters.AddWithValue("@FarmerType", rdltype.SelectedItem.Text);

Sachin SinghRank #66 · 26.2K reputationPosted Jan 3, 2023, 12:38 AM EST
Have you manually added the hardcoded value? It seems incorrect it should be like this (If radiobutton is not binding from code behind)
var selectedValue=rdltype.SelectedValue;To get text instead,
var selectedValue=rdlType.SelectedItem.Text;Garima BansalRank #1,555 · 1K reputationPosted Jan 3, 2023, 2:17 AM EST
Sachin Singh
i am using this way but still store null value in database
var selectedValue = rdltype.SelectedItem.Text;
cmd.Parameters.AddWithValue("@Type", selectedValue);
Sachin SinghRank #66 · 26.2K reputationPosted Jan 3, 2023, 2:34 AM EST
Do this
var selectedValue = Convert.ToString(rdltype.SelectedItem.Text); SqlCommand cmd= new SqlCommand("insert into yourTable(Type,..othercolumnnames) values(@Type,...othercolumnvaalues)"); cmd.Parameters.AddWithValue("@Type", selectedValue); cmd.ExecuteNonQuery();and make sure , in database the Type column is Varchar(150)
Rajeesh MenothRank #118 · 18.4K reputationPosted Jan 3, 2023, 5:04 AM EST
Hi,
You need to validate the following steps in your code.
1. Make sure what radio button value you are getting it before storing in the database. If you are getting the value in the backend code before storing it, then the issue is related to your database code.
2. Kindly refer to the following article - https://www.c-sharpcorner.com/UploadFile/009464/save-selected-data-of-radio-button-list-in-Asp-Net/