Click here to Skip to main content
15,917,642 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,
my scenario is I store a "status" column value as true/false.
i create a dropdown list with three option like 1.select status. 2. Active 3. De-Active.
My problem is that i am not able to compare these value to my status(true/false).
if you have any solution for that please give me.

thanks in advance
Posted

Try this,

XML
<asp:DropDownList ID="ddlStatus" runat="server">
    <asp:ListItem Text="Active" Value="1"></asp:ListItem>
    <asp:ListItem Text="De-Active" Value="0"></asp:ListItem>
    </asp:DropDownList>




if(ddlStatus.SelectedValue=="1") // For Active Status
            // Do Your Code
        else if(ddlStatus.SelectedValue=="0") // For De-Active Status
             // Do Your Code
 
Share this answer
 
I recommend an enumeration. Something as simple as the following may be enough:

public enum myStatus
{
  Inactive = 0 
,
  Active = 1
}


Then pass in the numeric value. You're not storing the true/false as strings, right? Right?

My article here[^] may give some more ideas.
 
Share this answer
 
When you have your drop down list, you could convert the selected status to a Boolean value before saving it to your database.

eg:

VB
if ddlStatus = ACTIVE then
  blnStatus = true
else
  blnStatus = false
end if


Another idea would be to have a StatusID column in your table that links back to your Status table (rather than true/false) - that was if you decide to add a new Status (say Pending, On Hold or whatever), you can simply add a new value to your Status table to display in your status dropdown list.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900