ASP.Net Yes/No fields bound to database

Posted on 2011-10-24
Last Modified: 2012-08-13
What is the best way to implement a yes/no field on an form. I have some fields that are answers to simple yes or no questions. The database field (SQL Server 2005) is an int, with 1 being yes and 0 being no. On the web form I want to display a Yes or No radio button style input, pulling from the database. The anwer can only be Yes OR no, and if the answer is yes I want to display a grid below the question. What is the best way to implement this? I'm using C# as code behind.
Question by:dodgerfan
    LVL 10

    Assisted Solution

    1. Read the table for that record

    2. read the objDS.Tables[0].Rows[0]["YesNoColumnName"].ToString() to string Variable

    3. use If Else condition

     if(_varYesNoValue == "1")
       // Display Grid
       //Hide Grid
    LVL 16

    Accepted Solution

    You can use conditional operator as given below. As the value is either 0 or 1 the table's column could be bit instead of int.

    string YesOrNo = objDS.Tables[0].Rows[0]["YesNoColumnName"].ToString();
    bool result = YesOrNo.Equals("1") ? true : false;

      //Show the grid
      //Some other logic


    Author Closing Comment

    Thanks for the tips. I got it working.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 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

    20 Experts available now in Live!

    Get 1:1 Help Now