【问题标题】:Data manipulation in Dropdownlist using DataSource使用 DataSource 在 Dropdownlist 中进行数据操作
【发布时间】:2018-07-23 07:36:16
【问题描述】:

我有这个 DropDowList,它使用 DataSource 来显示所有项目。哪个正在使用这个查询:

Select distinct [Word] from [Book] order by [Word]

假设查询显示以下单词。

  1. 苹果
  2. 橙色
  3. 芒果
  4. 香蕉
  5. 菠萝

现在我的问题是我想将 RadiobuttonList 中显示的所有数据转换为我想要的特定文本。例如,单词 Banana 到它的西班牙语单词 Platano。

下面是下拉菜单:

<asp:DropDownList ID="FruitDD" runat="server" DataSourceID="FruitSource" DataTextField="Value" DataValueField="Code" AppendDataBoundItems="True"> <asp:ListItem>- Select Fruit</asp:ListItem>
</asp:DropDownList>

这是我用来转换的代码。

FruitDD.Items[1].Text = "[string that I want]";

导致错误的原因:

索引超出范围。必须是非负数且小于 集合。参数名称:索引

有没有一种有效的方法可以使用 DataSource 进行转换?

【问题讨论】:

  • 查看 FruitDD 中有多少项目。 item的index不能大于等于item的count

标签: c# mysql asp.net datasource dropdown


【解决方案1】:

我已经有了答案。

FruitDD.DataBind();
FruitDD.Items[number].Text = "[string]";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 2018-05-04
    • 2023-03-23
    • 1970-01-01
    • 2019-12-04
    • 2017-04-10
    相关资源
    最近更新 更多