Solved

Radio Button Values from Database

Posted on 2013-01-07
9
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 15

Expert Comment

by:Navneet
ID: 38752491
Hi!

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

Thanks!
0
 
LVL 15

Expert Comment

by:Navneet
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 15

Assisted Solution

by:Navneet
Navneet 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:Navneet
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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