ASP.Net Yes/No fields bound to database

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.
dodgerfanAsked:
Who is Participating?
 
Easwaran ParamasivamCommented:
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;

if(result)
{
  //Show the grid
}
else
{
  //Some other logic
}

0
 
himanshutCommented:
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
 }
 else
 {
   //Hide Grid
 }
0
 
dodgerfanAuthor Commented:
Thanks for the tips. I got it working.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.