Solved

Reading boolean from DB

Posted on 2016-08-15
5
50 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 50

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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