Solved

Radio Button Values from Database

Posted on 2013-01-07
9
276 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

13 Experts available now in Live!

Get 1:1 Help Now