Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 57
  • Last Modified:

Reading boolean from DB

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
mcrmg
Asked:
mcrmg
  • 3
2 Solutions
 
Ryan ChongCommented:
>>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
 
mcrmgAuthor Commented:
thank you
0
 
Manoj PatilSr. Software EngineerCommented:
You need to do this
if (Active.Text == "True")
     Active.SelectedIndex=1;
else
    Active.SelectedIndex=2;

Open in new window

0
 
mcrmgAuthor Commented:
0
 
mcrmgAuthor Commented:
thank you
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now