G
Guest
Hello.
I am reading a value from a table and trying to determine if that value
exists in a list of values associated with a dropdownlist. If so, I select
the value, otherwise, I don't. I haven't been able to figure this operation
out so far.
Code:
if (reader["region_id"] != System.DBNull.Value)
{
if
(ddlApplicantRM.Items.Contains(ddlApplicantRM.Items.FindByValue(reader["region_id"].ToString())) == true)
{
ddlApplicantRM.SelectedValue =
reader["region_id"].ToString();
}
else
{
ddlApplicantRM.SelectedValue = "0";
}
}
Even though the value clearly exists in the list of values attached to the
dropdown, it never selects the value in the dropdown correctly. Is this the
proper way of doing what I am trying to accomplish? Does it matter if
region_id is an INT and the comparison function requires a string?
Thanks in advance for any suggestions or help.
I am reading a value from a table and trying to determine if that value
exists in a list of values associated with a dropdownlist. If so, I select
the value, otherwise, I don't. I haven't been able to figure this operation
out so far.
Code:
if (reader["region_id"] != System.DBNull.Value)
{
if
(ddlApplicantRM.Items.Contains(ddlApplicantRM.Items.FindByValue(reader["region_id"].ToString())) == true)
{
ddlApplicantRM.SelectedValue =
reader["region_id"].ToString();
}
else
{
ddlApplicantRM.SelectedValue = "0";
}
}
Even though the value clearly exists in the list of values attached to the
dropdown, it never selects the value in the dropdown correctly. Is this the
proper way of doing what I am trying to accomplish? Does it matter if
region_id is an INT and the comparison function requires a string?
Thanks in advance for any suggestions or help.