?
Solved

Reading boolean from DB

Posted on 2016-08-15
5
Medium Priority
?
54 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
[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
  • 3
5 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

770 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