[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


ASP.Net Yes/No fields bound to database

Posted on 2011-10-24
Medium Priority
Last Modified: 2012-08-13
What is the best way to implement a yes/no field on an asp.net 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

himanshut earned 1000 total points
ID: 37021582
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

Easwaran Paramasivam earned 1000 total points
ID: 37023257
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

ID: 37027679
Thanks for the tips. I got it working.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses

872 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