【发布时间】:2018-07-23 07:36:16
【问题描述】:
我有这个 DropDowList,它使用 DataSource 来显示所有项目。哪个正在使用这个查询:
Select distinct [Word] from [Book] order by [Word]
假设查询显示以下单词。
- 苹果
- 橙色
- 芒果
- 香蕉
- 菠萝
现在我的问题是我想将 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