Solved

Reading boolean from DB

Posted on 2016-08-15
5
51 Views
Last Modified: 2016-08-17
With EEs' help, this is the code in ASP.NET, it is a boolean type in sql
                                           <asp:DropDownList ID="Active" runat="server">                           
                                                <asp:ListItem value="">Select</asp:ListItem>
                                                <asp:ListItem value="1">Yes</asp:ListItem>			        
                                                <asp:ListItem value="0">No</asp:ListItem>			
                                           </asp:DropDownList>  

Open in new window


I have no problem saving selected value into sql, but I am not sure how to read it back to the frontend.

I have tried
                if (Active.Text == "True")
                    Active.Text = "1";
                else
                {
                    Active.Text = "0";
                }

Open in new window


and

Active.Text = reader["Active"].ToString();

Open in new window


But the dropdown list is not picking up the value....Can EEs give me some help?  thanks
0
Comment
Question by:mcrmg
  • 3
5 Comments
 
LVL 51

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41756602
>>but I am not sure how to read it back to the frontend
you need to set its SelectedIndex property

you can adapt and cstomize the 2nd way in this article:
Programmatically select an item in asp.net dropdownlist by text
http://techbrij.com/select-item-aspdotnet-dropdownlist-programmatically
0
 

Assisted Solution

by:mcrmg
mcrmg earned 0 total points
ID: 41756756
thank you
0
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 41757443
You need to do this
if (Active.Text == "True")
     Active.SelectedIndex=1;
else
    Active.SelectedIndex=2;

Open in new window

0
 

Author Closing Comment

by:mcrmg
ID: 41759203
0
 

Author Comment

by:mcrmg
ID: 41759204
thank you
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
How to close an asp.net web form using C# ? 4 45
Deploying to Azure 3 39
ASP.NET MVC identity 6 30
How come this regular expression allows "e"? 14 45
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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