Link to home
Start Free TrialLog in
Avatar of RecipeDan
RecipeDan

asked on

Radio Button Values from Database

Hello:

I have a form with radion buttons that I am I trying to show checked or not based on value in the database. The N is always checked even if the value is Y.

    <asp:RadioButtonList RepeatDirection="Horizontal" AutoPostBack="True" ID="Contract" runat="server">
    <asp:ListItem Value="Y">Y</asp:ListItem>
    <asp:ListItem Value="N">N</asp:ListItem>
    </asp:RadioButtonList>  

Open in new window


                if (reader["Contract"].ToString() == "Y")
                {
                    Contract.SelectedValue = "Y";
                }
                else
                {
                    Contract.SelectedValue = "N";
                }

Open in new window

Avatar of Navneet Hegde
Navneet Hegde
Flag of United States of America image

Hi!

Check if it's case-sensitive
reader["Contract"]..ToString().ToUpper() == "Y"

Thanks!
Hi!

I tried
                if ("Y" == "Y")
                {
                    Contract.SelectedValue = "Y";
                }
                else
                {
                    Contract.SelectedValue = "N";
                }

Open in new window


It seems to work good

Thanks!
Avatar of RecipeDan
RecipeDan

ASKER

All the Values are Upper Case in the Database.

@ navneethegde I get an unreachable code detected error message
SOLUTION
Avatar of Navneet Hegde
Navneet Hegde
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The Selected Value is always N even if the value being pulled from the database is Y
Yea!

That's why I want to check your code-behind to see where si the function calledtine in which rou
I made some changes I now I am getting an error message

Object reference not set to an instance of an object.

Contract.SelectedItem.Value = reader["Contract"].ToString(); 

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes. I know...I figured it out

Contract.SelectedValue = reader["Contract"].ToString();

Open in new window