On a radiobuttonlist I'm always getting .SelectedIndex = -1 even though I have selected one of the radio buttons. Change that to dropdownlist and it works. .NET C#
Posted on 2004-11-15
This is a good one. I'm seeing different behavior with radiobuttonlist versus drowdownlist even though they supposedly inheret the same properties from listcontrol
I created a radiobuttonlist and bound data to it via my page_load code
-- see data binding in page_load here --
// query db for cyclename and due date
string sql = "select distinct CycleName,DueDate " +
"from v_store_assignments " +
"where Source=2 " +
"and ChainName=@p_chainname " +
"and DueDate>=@p_duedatebegin and DueDate<= @p_duedateend " +
"order by DueDate asc";
System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
string dsn = ((string)(configurationAppSettings.GetValue("sqlConnection2_mr.ConnectionString", typeof(string))));
using (SqlConnection conn = new SqlConnection(dsn))
using (SqlCommand cmd = new SqlCommand(sql,conn))
_cyclelist.DataSource = cmd.ExecuteReader();
// I want to eventually display the visit date range along with the CycleName
//string displayfield =
_cyclelist.DataTextField = "CycleName";
_cyclelist.DataValueField = "DueDate";
-- end data binding here--
I then select from the list a single radio button and select another button called view report. That view report button calls code that retrieves the value of the button I selected and sets it as a crystal report parameter.
Now when I try to retrieve the value via the .selectedvalue:
I get null.
When I check for the .SelectedIndex I always get -1.
Then when I change the radiobuttonlist to a dropdownlist all works. Argghhh.
So, does anybody know why the radiobuttonlist would behave differently than the dropdownlist?