Solved

Radio Button Values from Database

Posted on 2013-01-07
9
279 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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