【问题标题】:Trying to set dropdown selected value equal to part of string尝试将下拉选择的值设置为字符串的一部分
【发布时间】:2015-06-28 11:14:06
【问题描述】:

我正在尝试选择下拉列表中选择的值等于某个值,如下所示:

 ddlRemark.SelectedValue = ddlRemark.Items.FindByText("string").Value

Dropdownlist 包含数据文本值,例如

1)B - In case of no deduction on account of declaration under section 197A

2)C - In case of deduction of tax at higher rate due to non-availability of PAN

我的问题是以编程方式选择下拉值,它匹配一些从其他地方获取的字符串值,在我的例子中是从数据库中获取的。

获取的值类似于 A B C 等。

所以,如果我的值为B,下拉列表应选择为C - In case of deduction of tax at higher rate due to non-availability of PAN

那么,如何指定类似ddlRemark.SelectedValue = ddlRemark.Items.FindByText("string").Value 中的内容来代替字符串。 例如,字符串可以包含从 A 或 B 开始的内容,等等

【问题讨论】:

  • 发布您的下拉列表代码以获得想法?

标签: asp.net vb.net drop-down-menu


【解决方案1】:

DropDownLists Text 和 Values 可以不同

想象一下这是你的 ddl:

<asp:DropDownList ID="ddlRemark" runat="server">
                <asp:ListItem Value="B">B - In case of no deduction on account of declaration under section 197A</asp:ListItem>
                <asp:ListItem Value="C">C - In case of deduction of tax at higher rate due to non-availability of PAN</asp:ListItem>
            </asp:DropDownList>

并直接使用值

if (ddlRemark.SelectedValue == "B")
    //your code
else if (ddlRemark.SelectedValue == "C") 
    //your code
else
    //...

【讨论】:

  • 在我的情况下这是不可能的,因为我将它绑定到 Value 属性的 ID 值
猜你喜欢
  • 2014-05-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-21
  • 1970-01-01
  • 2016-05-07
  • 2019-11-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多