ASPxListBox 项目转为字符串
这应该很容易,但我没能做到这一点。我打开了 ASPxListBox 的复选框选项。所以我想在一个字符串中选择项目。像这样:
项目1,项目4,项目9
等。
请注意,它们应该被“,”分隔,并删除最后一个逗号。
尝试过类似的方法,但行不通:(
StringBuilder sb = new StringBuilder();
for (int i = 0; i < lb1.Items.Count; i++)
sb.Append(lb1.Items[i].Selected ? lb1.Items[i].Text + "," : "");
TextBox1.Text = sb.ToString();
我之前问过类似的问题,但由于我没有提到这是 ASPxListBox,所以我得到的建议不起作用。
所以,这是 Visual Studio 2008、Devexpress 9.3 和 .NET Framework 3.5
谢谢。
This should be easy, but I'm failing to do this. I have ASPxListBox with checkbox option turned on. So I'd like to have selected items in one string. Like this:
item1,item4,item9
and so on.
Notice that they should be divided by "," and last comma deleted.
Tried something like this, but won't work:
StringBuilder sb = new StringBuilder();
for (int i = 0; i < lb1.Items.Count; i++)
sb.Append(lb1.Items[i].Selected ? lb1.Items[i].Text + "," : "");
TextBox1.Text = sb.ToString();
(I asked similar question before, but as I havent mention that this is ASPxListBox, suggestions I got wont works.
So, this is Visual Studio 2008, Devexpress 9.3 and .NET framework 3.5
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不熟悉 ASPxListBox,但是您不能循环遍历然后通过获取子字符串删除最后一个逗号吗?
I'm not familiar with
ASPxListBox
, but couldn't you just loop through and then remove the last comma by getting the substring?@keyboardP:我认为你的解决方案相当不错,所以+1。
此外,您可以在 DevExpress 代码中心找到类似的解决方案:
http://www .devexpress.com/Support/Center/e/E2625.aspx
@keyboardP: your solution is rather ok on my mind, so +1.
Moreover, you can find a similar solution in the DevExpress code central:
http://www.devexpress.com/Support/Center/e/E2625.aspx
我不熟悉 aspxlistbox 但你可以写这样的东西 -
I am not familiar with aspxlistbox but You can write something like this-