Solved

Radio Button Values from Database

Posted on 2013-01-07
9
277 Views
Last Modified: 2013-01-09
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

0
Comment
Question by:RecipeDan
  • 4
  • 4
9 Comments
 
LVL 15

Expert Comment

by:navneethegde
ID: 38752491
Hi!

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

Thanks!
0
 
LVL 15

Expert Comment

by:navneethegde
ID: 38752538
Hi!

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

Open in new window


It seems to work good

Thanks!
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 38752700
All the Values are Upper Case in the Database.

@ navneethegde I get an unreachable code detected error message
0
 
LVL 15

Assisted Solution

by:navneethegde
navneethegde earned 50 total points
ID: 38752908
HI!

what does this gives you

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

Open in new window


Can you  paste the event of code-behind where you calling this.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:RecipeDan
ID: 38752962
The Selected Value is always N even if the value being pulled from the database is Y
0
 
LVL 15

Expert Comment

by:navneethegde
ID: 38752971
Yea!

That's why I want to check your code-behind to see where si the function calledtine in which rou
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 38760775
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

0
 
LVL 41

Accepted Solution

by:
guru_sami earned 450 total points
ID: 38760799
Because you are never setting any item as Selected i.e. your SelectedItem is null and when you try setting it's Value,  you get that exception.
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 38760952
Yes. I know...I figured it out

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

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now