与真/假的比较 [英] comparision with true/false

查看:93
本文介绍了与真/假的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

我的情景是我将状态列值存储为true / false。

i创建一个下拉列表,其中包含三个选项,如1.select status 。 2.活动3.停用。

我的问题是我无法将这些值与我的状态(真/假)进行比较。

如果你有任何请给我解决方案。



提前感谢

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

推荐答案

试试这个,



Try this,

<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


我建​​议使用枚举。以下简单的东西就足够了:



I recommend an enumeration. Something as simple as the following may be enough:

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





然后传入数值。你没有将true / false存储为字符串,对吗?对吗?



我的文章这里 [ ^ ]可能会提供更多想法。



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.

当你有下拉列表时,可以将所选状态转换为布尔值,然后再将其保存到数据库中。



例如:



When you have your drop down list, you could convert the selected status to a Boolean value before saving it to your database.

eg:

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





另一个想法是在你的表中有一个StatusID列链接回你的Status表(而不是true / false) - 那个如果您决定添加新状态(说Pending,On Hold或其他),您只需在状态表中添加一个新值即可显示在状态下拉列表中。



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.


这篇关于与真/假的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆